473,624 Members | 2,281 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Tkinter code (with pmw) executing to soon please help

Instead of creating my buttons and waiting for me to press them to
execute they are executing when I create them and won't do my callback
when I press them.. thanks for any help in advance

button[num] = Tkinter.Button( frame,text = returnstring,
command=callbac k(returnstring) )#

this line executes on creation

my output on startup is (should output when I choose an option)

1 String pad
10 Chorus
25 Reverb
30 Mixer
The buttons do label correctly.


title = 'csd instrument list'

# Import Pmw from this directory tree.
import sys
sys.path[:0] = ['../../..']

import Tkinter
import Pmw
import csoundroutines

class Demo:
def __init__(self, parent):
frame = Tkinter.Frame(p arent)
frame.pack(fill = 'both', expand = 1)

button = {}

instr = [[]]
instr = csoundroutines. csdInstrumentLi st2(sys.argv[1])

num = 0 #instr_number

buttonBox = Pmw.ButtonBox(p arent)
for i in range(0, len(instr.instr num)):
num += 1
returnstring = instr.instrnum[i] +' '+ str(instr.comme nts[i])
#printstring = zz + x[num]
button[num] = Tkinter.Button( frame,text = returnstring,
command=callbac k(returnstring) )#kinter.Button str(x[0]) + ' ' + x[1])# +
comments)
button[num].pack()
#returnstring = zz
button[num].grid(column=nu m, row =
0)#,command=cal lback(returnstr ing))
#button[num].pack()

frame.grid_rowc onfigure(3, weight=1)
frame.grid_colu mnconfigure(3, weight=1)
frame.pack()
def callback(text):
print text
############### ############### ############### ############### ##########

# Create demo in root window for testing.
if __name__ == '__main__':
global filename
filename = (sys.argv[1])
root = Tkinter.Tk()
Pmw.initialise( root)
root.title(titl e)

exitButton = Tkinter.Button( root, text = 'Exit', command =
root.destroy)
exitButton.pack (side = 'bottom')
widget = Demo(root)
root.mainloop()

http://www.dexrow.com

Jan 14 '07 #1
6 1873
<Er*********@ms n.comescribió en el mensaje
news:11******** *************@l 53g2000cwa.goog legroups.com...
Instead of creating my buttons and waiting for me to press them to
execute they are executing when I create them and won't do my callback
when I press them.. thanks for any help in advance
This is a very frequent beginner's mistake. You are *calling* the event
handler at the moment you create the buttons. You have to provide a
*callable* but not call it yet.
button[num] = Tkinter.Button( frame,text = returnstring,
command=callbac k(returnstring) )#
So `callback` should return a function, like this:

def callback(text):
def handler(event):
print text

--
Gabriel Genellina

Jan 14 '07 #2
Gabriel Genellina wrote:
>... So `callback` should return a function, like this:

def callback(text):
def handler(event):
print text
Even better than that:
def callback(text):
def handler(event):
print text
return handler

Otherwise callback returns the spectacularly un-useful value None.

--Scott David Daniels
sc***********@a cm.org
Jan 14 '07 #3
C:\dex_tracker\ csdlist.py bay-at-night.csd
Traceback (most recent call last):
File "C:\dex_tracker \csdlist.py", line 58, in
root.mainloop()
File "C:\Python25\li b\lib-tk\Tkinter.py", line 1023, in mainloop
self.tk.mainloo p(n)
File "../../..\Pmw\Pmw_1_2\ lib\PmwBase.py" , line 1751, in __call__
File "../../..\Pmw\Pmw_1_2\ lib\PmwBase.py" , line 1777, in _reporterror
TypeError: unsupported operand type(s) for +: 'type' and 'str'
Script terminated.

It doesn't like the return handler part of it.

Scott David Daniels wrote:
Gabriel Genellina wrote:
... So `callback` should return a function, like this:

def callback(text):
def handler(event):
print text

Even better than that:
def callback(text):
def handler(event):
print text
return handler

Otherwise callback returns the spectacularly un-useful value None.

--Scott David Daniels
sc***********@a cm.org
Jan 14 '07 #4
button[num] = Tkinter.Button( frame,text = returnstring,
command=callbac k(returnstring) )#

I understand this part of it

def callback(text):
def handler(event):
print text

It stopped calling it automaticaly but will not do anything when I
click on the button. Does something have to change on this line as
well.

button[num] = Tkinter.Button( frame,text = returnstring,
command=callbac k(returnstring)


Gabriel Genellina wrote:
<Er*********@ms n.comescribió en el mensaje
news:11******** *************@l 53g2000cwa.goog legroups.com...
Instead of creating my buttons and waiting for me to press them to
execute they are executing when I create them and won't do my callback
when I press them.. thanks for any help in advance

This is a very frequent beginner's mistake. You are *calling* the event
handler at the moment you create the buttons. You have to provide a
*callable* but not call it yet.
button[num] = Tkinter.Button( frame,text = returnstring,
command=callbac k(returnstring) )#

So `callback` should return a function, like this:

def callback(text):
def handler(event):
print text

--
Gabriel Genellina
Jan 14 '07 #5
Er*********@msn .com wrote:
Scott David Daniels wrote:
>Gabriel Genellina wrote:
>... So `callback` should return a function, like this:

def callback(text):
def handler(event):
print text

Even better than that:
def callback(text):
def handler(event):
print text
return handler

Otherwise callback returns the spectacularly un-useful value None.
C:\dex_tracker\ csdlist.py bay-at-night.csd
Traceback (most recent call last):
File "C:\dex_tracker \csdlist.py", line 58, in
root.mainloop()
File "C:\Python25\li b\lib-tk\Tkinter.py", line 1023, in mainloop
self.tk.mainloo p(n)
File "../../..\Pmw\Pmw_1_2\ lib\PmwBase.py" , line 1751, in __call__
File "../../..\Pmw\Pmw_1_2\ lib\PmwBase.py" , line 1777, in _reporterror
TypeError: unsupported operand type(s) for +: 'type' and 'str'
Script terminated.

It doesn't like the return handler part of it.
Probably because a Tkinter.Button command callback doesn't accept any
arguments. Try

def callback(text):
def handler():
print text
return handler

Note that 'make_callback' would be a better name than 'callback' because the
function 'callback' actually creates the callback (called 'handler').

Peter
Jan 14 '07 #6
<Er*********@ms n.comescribió en el mensaje
news:11******** **************@ a75g2000cwd.goo glegroups.com.. .
button[num] = Tkinter.Button( frame,text = returnstring,
command=callbac k(returnstring) )#

I understand this part of it

def callback(text):
def handler(event):
print text
It stopped calling it automaticaly but will not do anything when I
click on the button. Does something have to change on this line as
well.
Sorry, I overlooked your example. For a button, command should be a function
with no arguments (and I forget to return the handler, as someone already
pointed out):

def callback(text):
def handler():
print text
return handler

--
Gabriel Genellina

Jan 14 '07 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
3594
by: wang xiaoyu | last post by:
Hello,everyone. my program runs well in windows,i use tkSimpleDialog to receive some input,but when i copy my program into Linux RH8.0,entrys in my tkSimpleDialog derived Dialog have a vital problem:only one entry can receive key event,'tab' key to navigate between entrys is not valid too,when i use mouse to focus a entry(which can not navigate through 'tag' key),no matter what key i pressed the entry receive no reply.But in window they...
0
3060
by: Bruce Davis | last post by:
I'm having a problem on windows (both 2000 and XP) with a multi-threaded tkinter gui application. The problem appears to be a deadlock condition when a child thread pops up a Pmw dialog window in the context of a main window. The problem does not occur on HPUX or Linux. The following simple example code illustrates the problem and the work around I've come up with; However, I'd like, very much, to get rid of the kludgy work around....
2
4625
by: Stewart Midwinter | last post by:
I would like to link the contents of three OptionMenu lists. When I select an item from the first list (call it continents), the contents of the 2nd list (call it countries) would update. And in turn the contents of the 3rd list (call it states would be updated by a change in the 2nd list. If anyone can share a recipe or some ideas, I'd be grateful! Here's some sample code that displays three OptionMenus, but doesn't update the list...
0
2123
by: Stewart Midwinter | last post by:
I've got a Tkinter app that draws three histograms. At this point I am simulating real data by drawing rectangles whose size is defined by random numbers; in the future there would be real data coming from a server. I want to redraw the rectangles every time I press the Again button. This works for me, but I get an extra set of rectangles each time I press the Again button. How to get rid of this effect? Here's the app so you can see...
1
6338
by: midtoad | last post by:
I'm trying to display a GIF image in a label as the central area to a Tkinter GUI. The image does not appear, though a space is made for it. Why is this so? I notice that I can display a GIF image in the central area of a simple menu-bar app as shown below in the first code sample. But, when I set up my app with a class, as shown below in the second code sample, the image disappears. How can I correct this? I'm sure the answer would...
7
11895
by: SeeBelow | last post by:
Do many people think that wxPython should replace Tkinter? Is this likely to happen? I ask because I have just started learning Tkinter, and I wonder if I should abandon it in favor of wxPython. Mitchell Timin -- "Many are stubborn in pursuit of the path they have chosen, few in
1
1814
by: Laura Conrad | last post by:
I'm writing a GUI application in python, which will need to work on a Windows XP box. Mostly it does, but the feature where results are graphed in real time, which works fine on a debian LINUX box, refuses to run on windows. I'm currently running on cygwin, and changing to a standalone python app would be a pain, but possible. The BltGraph demo which comes with Pmw also refuses to run. The code in that case is:
4
13756
by: Alex Hunsley | last post by:
Can anyone recommend some code for creating drop-down menus in tkinter? To be absolutely clear, here's an example of a drop-down: http://www.google.co.uk/preferences?hl=en (see the language selection widget) I've found the odd bit of code here and there, such as: http://infohost.nmt.edu/tcc/cgi/pre.cgi?file=/u/www/docs/tcc/help/lang/python/mapping/dropdown.py alex
0
2344
by: Stewart Midwinter | last post by:
I have a Tkinter app running on cygwin. It includes a Test menu item that does nothing more than fetch a directory listing and display it in a Toplevel window (I'd use a tkMessageBox showinfo widget, but for some reason the text is invisible on cygwin). After I close the Toplevel widget, all of the menus in my app behave as though they have no contents to them, i..e I can press on the File menu button, and see it depress, but the Exit...
0
8177
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8681
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8629
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8488
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7170
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4084
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4183
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2611
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1488
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.