[Tutor] Pygubu designer question
Phil
phillor9 at gmail.com
Tue Feb 1 01:53:02 EST 2022
I've spent most of the afternoon experimenting with Pygubu builder. I
haven't done much with Tkinter so my knowledge is a bit thin. Pygubu
uses a callback mechanism rather than the bind method that I'm more
familiar with. What I'm trying to achieve is read the contents of an
edit box when returned is pressed. I've done this in the past with
"entry.bind('Return', on_change)" if I remember correctly.
This is taken from the file that Pygubu generates:
self.entry1.configure(exportselection='true', relief='flat',
takefocus=False, validate='focusout')
self.entry1.delete('0', 'end')
self.entry1.insert('0', _text_)
self.entry1.place(anchor='sw', height='30', width='100',
x='10', y='100')
self.entry1.configure(validatecommand=self.callback)
There are other entry1 options but I think validatecommand is all that I
need. I've searched the Internet for any clues but haven't turned up
anything relevant.
My programme includes the following:
# define the function callbacks
def on_button1_click():
messagebox.showinfo('Message', 'You pressed me') # no problems here
def callback(self):
#print(entry1.get()) # entry1 is unknown and self.entry1 didn't
help but that's another problem
print('here')
# Configure callbacks
callbacks = {
'on_button1_clicked': on_button1_click,
'callback' : callback # This doesn't look to be correct
}
builder.connect_callbacks(callbacks)
The word 'here' is printed when the programme is first run. I press the
button so that the entry box loses focus and that's when the error
message is displayed.
The error message is Exception in Tkinter callback
Traceback (most recent call last):
File "/usr/lib/python3.9/tkinter/__init__.py", line 1892, in __call__
return self.func(*args)
TypeError: 'NoneType' object is not callable
I know that I need to read up on Tkinter but someone who may be familiar
with callbacks and Pygubu may be able to help.
--
Regards,
Phil
More information about the Tutor
mailing list