Python GUI questions

Terry Reedy tjreedy at udel.edu
Tue Mar 19 23:21:06 EDT 2013


On 3/19/2013 10:16 PM, Ranting Rick wrote:
> import tkinter as tk
> from tkinter.constants import LEFT
>
> def cbButton(self):
>      print('I should do something here!')
>
> root = tk.Tk()
> root.title("Window")
> w=tk.Label(root, text="Enter a string")
> w.pack(side=LEFT)
> e1 = tk.Entry(root, bd=5)
> e1.pack(side=LEFT)
> b=tk.Button(root, text="Count", command=cbButton)
> b.pack(padx=5, pady=5)
> root.mainloop()

when I run this, and click the button, I get
Exception in Tkinter callback
Traceback (most recent call last):
   File "C:\Programs\Python33\lib\tkinter\__init__.py", line 1442, in 
__call__
     return self.func(*args)
TypeError: cbButton() missing 1 required positional argument: 'self'

when I remove 'self' from cbButton, I get the expected
I should do something here!

When I enter something in the Entry box and hit return, nothing happens. 
I presume that is because the example is not complete.

-- 
Terry Jan Reedy




More information about the Python-list mailing list