I'm rather new to both Tkinter and Classes, so whatever I'm doing wrong probably seems really stupid. Just bare with me, here. The reference to the buttons seems to disappear after the __init__ method, so when I try to call them and change them in another method, I get an attribute error. -
def __init__(self):
-
self.window = Tk()
-
self.left = Frame(self.window, relief='sunken', border=1)
-
self.middle = Frame(self.window, relief='sunken', border=1)
-
self.right = Frame(self.window, relief='sunken', border=1)
-
self.left.grid(column=0, row=0)
-
self.middle.grid(column=2, row=0)
-
self.right.grid(column=4, row=0)
-
-
self.B1 = Button(self.left, text=' - ', command=self.changeButton(1))
-
self.B2 = Button(self.middle, text=' - ', command=self.changeButton(2))
-
self.B3 = Button(self.right, text=' - ', command=self.changeButton(3))
-
self.B4 = Button(self.left, text=' - ', command=self.changeButton(4))
-
self.B5 = Button(self.middle, text=' - ', command=self.changeButton(5))
-
self.B6 = Button(self.right, text=' - ', command=self.changeButton(6))
-
self.B7 = Button(self.left, text=' - ', command=self.changeButton(7))
-
self.B8 = Button(self.middle, text=' - ', command=self.changeButton(8))
-
self.B9 = Button(self.right, text=' - ', command=self.changeButton(9))
-
-
self.B1.pack()
-
self.B2.pack()
-
self.B3.pack()
-
self.B4.pack()
-
self.B5.pack()
-
self.B6.pack()
-
self.B7.pack()
-
self.B8.pack()
-
self.B9.pack()
-
One of the methods that raises the AttributeError: -
def gameClear(self):
-
self.B1['text'] = ' - '
-
self.B2['text'] = ' - '
-
self.B3['text'] = ' - '
-
self.B4['text'] = ' - '
-
self.B5['text'] = ' - '
-
self.B6['text'] = ' - '
-
self.B7['text'] = ' - '
-
self.B8['text'] = ' - '
-
self.B9['text'] = ' - '
-
2 1668
I prefer to call the config() method of Tkinter objects. Try: - #
-
def gameClear(self):
-
self.B1.config(text=' - ')
I prefer to call the config() method of Tkinter objects. Try: - #
-
def gameClear(self):
-
self.B1.config(text=' - ')
Here is a discussion on sub-classing and instanciating Tk() and its subordinates.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Josh |
last post by:
Caution, newbie approaching...
I'm trying to come up with a very simple Tkinter test application that
consists of a window with a drop-down menu bar at the top and a grid
of colored rectangles...
|
by: mksql |
last post by:
New to Tkinter. Initially, I had some code that was executing button commands at
creation, rather than waiting for user action. Some research here gave me a
solution, but I am not sure why the...
|
by: Paul A. Wilson |
last post by:
I'm new to Tkinter programming and am having trouble creating a
reusable button bar... I want to be able to feed my class a dictionary
of button names and function names, which the class will make....
|
by: Elaine Jackson |
last post by:
I've got a script where a button gets pushed over and over: to cut down on the
carpal tunnel syndrome I'd like to have the button respond to presses of the
Enter key as well as mouse clicks; can...
|
by: dakman |
last post by:
Recently, I have been needing to do this alot and I can never find a
way around it, the main reason I want to do this is because for example
in the application I am making right now, it creates a...
|
by: Fuzzyman |
last post by:
Hello all,
I have some Tkinter buttons that display images. I would like to change
these to 'active' images when the mouse is over the button.
I see that the button widget can take an...
|
by: Jay |
last post by:
I'm having a problem using lambda to use a command with an argument for
a button in Tkinter.
buttons = range(5)
for x in xrange(5):
buttons = Button(frame, text=str(x+1), command=lambda:...
|
by: vagrantbrad |
last post by:
I've created a short test program that uses tkFileDialog.askdirectory
to help the user input a path into a tk entry widget. The problem I'm
having is that when I run the code as listed below, the...
|
by: akineko |
last post by:
Hello everyone,
I'm trying to implement a virtual instrument, which has buttons and
displays, using Tkinter+Pmw.
One of items on the virtual instrument is a round button.
This is imitating a...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
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...
|
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,...
|
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...
|
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...
| |