473,378 Members | 1,427 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Working with Widget after Instance loses the reference

I made the mistake of creating an instance of a widget and assigning it
to a name I'd already used. Now, if I use root.children or
root.slaves(), I can see the "lost" widget, but can I do anything else
with the string of numbers that shows up when I use root.children? I'd
like to destory the widget, for example. it would be even better if I
could create a new name and have it reference the "lost" widget.

Of course, I can just kill my toplevel and start over.

Jul 31 '06 #1
2 1427
On Mon, 2006-07-31 at 11:15 -0700, Al in Dallas wrote:
I made the mistake of creating an instance of a widget and assigning it
to a name I'd already used. Now, if I use root.children or
root.slaves(), I can see the "lost" widget, but can I do anything else
with the string of numbers that shows up when I use root.children? I'd
like to destory the widget, for example. it would be even better if I
could create a new name and have it reference the "lost" widget.

Of course, I can just kill my toplevel and start over.

Consider the following code run in the python shell:
>>from Tkinter import *
r = Tk()
b1 = Button(r, text='test')
b1.pack()
b2 = Button(r, text='test2')
b2.pack()
r.children
{'-1210160564': <Tkinter.Button instance at 0xb7de6a4c>, '-1210225748':
<Tkinter.Button instance at 0xb7dd6bac>}
>>r.slaves()
[<Tkinter.Button instance at 0xb7dd6bac>, <Tkinter.Button instance at
0xb7de6a4c>]
>>b1 = 'xxx'
b1.destroy()
Traceback (most recent call last):
File "<stdin>", line 1, in ?
AttributeError: 'str' object has no attribute 'destroy'
>>b1 = r.slaves()[0]
b1.destroy()

So, as long as you know what your widget instance is in root.slaves() or
root.children you can assign it to a new name.


--
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.

Aug 1 '06 #2
John McMonagle wrote:
On Mon, 2006-07-31 at 11:15 -0700, Al in Dallas wrote:
[example of "losing" a widget]
Consider the following code run in the python shell:
>from Tkinter import *
r = Tk()
b1 = Button(r, text='test')
b1.pack()
b2 = Button(r, text='test2')
b2.pack()
r.children
{'-1210160564': <Tkinter.Button instance at 0xb7de6a4c>, '-1210225748':
<Tkinter.Button instance at 0xb7dd6bac>}
>r.slaves()
[<Tkinter.Button instance at 0xb7dd6bac>, <Tkinter.Button instance at
0xb7de6a4c>]
>b1 = 'xxx'
b1.destroy()
Traceback (most recent call last):
File "<stdin>", line 1, in ?
AttributeError: 'str' object has no attribute 'destroy'
>b1 = r.slaves()[0]
b1.destroy()


So, as long as you know what your widget instance is in root.slaves() or
root.children you can assign it to a new name.
Since I've been leaving my shell open, I jumped in and tried:

recoveredlabel = root.slaves()[6]

And after I verified I could manipulate the widget with that
name, I executed:

<original-widget-name= recoveredlabel

Now the only difference between where I was (before I screwed up)
and where I am is that I've got this extra variable named
"recoveredlabel."

Thanks.

Now, do you have any advice on learning the syntax for dealing
with Tix megawidgets in Python? I guess my alternative is to
learn how to use Elmer or SWIG so I can hide all the Python
I've inherited "under the hood" and write my GUI in Tcl/Tk.

Aug 1 '06 #3

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

Similar topics

3
by: bigbinc | last post by:
I have used the 'entry' tk widget to get text values, I am now using 'Text' but I cant seem to use 'get' method. The TK docs say use get(index1, index2), I tried numbers and get an error ...
8
by: Harlin Seritt | last post by:
I have the following script. Two widgets call the same function. How can I tell inside of the called function which button called it?: def say_hello(): print 'hello!' print widget root =...
6
by: William Gill | last post by:
I am trying to get & set the properties of a widget's parent widget. What I have works, but seems like a long way around the block. First I get the widget name using w.winfo_parent(), then i...
1
by: Shankar Iyer (siyer | last post by:
Hi, I am still new to Python and Tkinter, so I apologize in advance if I do not word my question optimally. I am trying to use a frame widget as the parent for other widgets. There is a class...
13
by: Max | last post by:
Hi There! I'm having a mysterious error right after I login using Forms Authentication in my ASP.NET app. Below is the error... Exception Details: System.NullReferenceException: Object...
7
by: Rich Grise | last post by:
OK, I don't know if this is Off-Topic for the group(s), because "QT" isn't "Pure C++", and Slackware is a distro, but those guys are sharp. :-) And I've crossposted to sci.electroncs.design because...
3
by: mariox19 | last post by:
Are Tkinter widgets running on their own thread? If I try to make a simple application that will print the letters A to Z to a Tkinter Text widget, and I space the printing of each letter by 1...
4
by: skanemupp | last post by:
when calling function hmm here, what do i get? the widget i clicked on? if i have a canvs on wich i have a bitmap and i click on the bitmap, is the event.widget then the bitmap? can i get info...
275
by: Astley Le Jasper | last post by:
Sorry for the numpty question ... How do you find the reference name of an object? So if i have this bob = modulename.objectname() how do i find that the name is 'bob'
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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 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.