473,396 Members | 1,891 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,396 software developers and data experts.

Tkinter root window problem

rhitam30111985
112 100+
hi all.. python noob here.. i am creating a GUI for an applcation... now i was just testing the working of askstring :
Expand|Select|Wrap|Line Numbers
  1. from tkSimpleDialog import askstring
  2. string=askstring('site','enter site:')
  3. print string
  4.  
now.. an extra empty window just pops up.. so i include NoDefaultRoot in th \e following manner:
Expand|Select|Wrap|Line Numbers
  1. from Tkinter import *
  2. NoDefaultRoot()
  3. from tkSimpleDialog import askstring
  4. string=askstring('site','enter site:')
  5. print string
  6.  
it then gives the following set of errors:
Traceback (most recent call last):
File "./check2.py", line 5, in ?
string=askstring('site','enter site:')
File "/usr/lib/python2.4/lib-tk/tkSimpleDialog.py", line 304, in askstring
d = _QueryString(title, prompt, **kw)
File "/usr/lib/python2.4/lib-tk/tkSimpleDialog.py", line 282, in __init__
_QueryDialog.__init__(self, *args, **kw)
File "/usr/lib/python2.4/lib-tk/tkSimpleDialog.py", line 172, in __init__
parent = Tkinter._default_root
AttributeError: 'module' object has no attribute '_default_root'
any idea whats wrog? or any alternative way to stop the default window from appearing?
Aug 30 '07 #1
8 4730
bartonc
6,596 Expert 4TB
The first method is correct.

The "extra" window is actually the application. It will eventually hold your main window. At this point, it is there to get all the event system, etc. rolling.
Aug 30 '07 #2
rhitam30111985
112 100+
yes but the problem still exists.. anyhow,, here is something else on similar lines:
Expand|Select|Wrap|Line Numbers
  1. from Tkinter import *
  2. from tkSimpleDialog import askstring
  3. win=Tk()
  4. ti={1:[2,4,5,6],3:[4,8,7,9,0],4:[5,5,6]}
  5. enter=askstring('','')
  6. for tag,num in ti.items():
  7.     if enter in num:
  8.         Label(text=tag,width=20).pack()
  9. win.mainloop()
  10.  
above program ideally should give me a window with 1 and 4 as its labels... but it gives an empty window... where am i going wrong?
Aug 31 '07 #3
bartonc
6,596 Expert 4TB
yes but the problem still exists.. anyhow,, here is something else on similar lines:
Expand|Select|Wrap|Line Numbers
  1. from Tkinter import *
  2. from tkSimpleDialog import askstring
  3. win=Tk()
  4. ti={1:[2,4,5,6],3:[4,8,7,9,0],4:[5,5,6]}
  5. enter=askstring('','')
  6. for tag,num in ti.items():
  7.     if enter in num:
  8.         Label(text=tag,width=20).pack()
  9. win.mainloop()
  10.  
above program ideally should give me a window with 1 and 4 as its labels... but it gives an empty window... where am i going wrong?
Looks like
  • Label() needs a parent window
  • The only available window is win (not the dialog)
  • Label() text might need to be a string (str(tag)), but ints may get converted
One way to get dictionaries to automatically make string type keys is:
Expand|Select|Wrap|Line Numbers
  1. dd = dict(1=[2,3,4])
Aug 31 '07 #4
rhitam30111985
112 100+
well ints do get converted in python V2.4.. also if i change line 8 to the following:
Expand|Select|Wrap|Line Numbers
  1. Label(win,text=tag,width=20).pack()
  2.  
which is unnecessary since it will use the default window ie win(ie Label wont need a parent window)... it still gives the same output

what to do?
Aug 31 '07 #5
bartonc
6,596 Expert 4TB
well ints do get converted in python V2.4.. also if i change line 8 to the following:
Expand|Select|Wrap|Line Numbers
  1. Label(win,text=tag,width=20).pack()
  2.  
which is unnecessary since it will use the default window ie win(ie Label wont need a parent window)... it still gives the same output

what to do?
Sorry. I didn't see that IF statement in there:
Expand|Select|Wrap|Line Numbers
  1. from Tkinter import *
  2. from tkSimpleDialog import askstring
  3. win=Tk()
  4. ti={1:[2,4,5,6],3:[4,8,7,9,0],4:[5,5,6]}
  5. enter=askstring('','')
  6. for tag,num in ti.items():
  7.     Label(text=tag,width=20).pack()
  8. win.mainloop()
Works. I cant' imagine what you are attempting with:
Expand|Select|Wrap|Line Numbers
  1.         if enter in num:
Aug 31 '07 #6
rhitam30111985
112 100+
ok here is a snippet of what i am actually working on:
Expand|Select|Wrap|Line Numbers
  1. import sys
  2. from Tkinter import *
  3. root = Tk()
  4. widget=Toplevel()
  5. win2=Toplevel()
  6. sub=Listbox(widget)
  7. sbar=Scrollbar(widget)
  8. sbar.config(command=sub.yview)
  9. sub.config(yscrollcommand=sbar.set)
  10. sbar.pack(side=RIGHT,fill=Y) 
  11. sub2=Listbox(win2)
  12. sbar2=Scrollbar(win2)
  13. sbar2.config(command=sub2.yview)
  14. sub2.config(yscrollcommand=sbar2.set)
  15. sbar2.pack(side=RIGHT,fill=Y)
  16. i=0
  17. wordlist=['qqe','rrt','ytgh','ihj']
  18. def enter():
  19.     sub2.insert('end',sub.curselection())
  20.     sub2.pack()
  21.  
  22. def writesub():
  23.     global i
  24.     sub.insert('end',wordlist[i])
  25.     i+=1
  26.     if i==len(wordlist)-1:
  27.         i=0
  28.     sub.pack(expand=YES,fill=BOTH)
  29. mainbutton=Button(root,text="enter text",command=writesub).pack(expand=YES,fill=BOTH)
  30. exitbutton=Button(root,text='QUIT',command=sys.exit).pack(fill=BOTH,expand=YES)
  31. enter()
  32. root.mainloop()
  33.  
now as i click the button " enter text" , the words in the wordlist get appended as expected in "sub" Listbox.. at the same time.. what i want is if i click any of the words in this list box.. it should get appended in the "sub2" listbox ... which is not happening ... it is just giving a blank window..
Sep 3 '07 #7
rhitam30111985
112 100+
i also added the following in line 19:
Expand|Select|Wrap|Line Numbers
  1. sub2.insert('end',sub.get(sub.curselection()))
  2.  
now the problem is that i have to click the button everytime i have to append the selected string in the sub list box in the sub2 listbox

how do i get around it?
Sep 4 '07 #8
rhitam30111985
112 100+
hey everyone .. never mind... problem solved.... didnt create a binding event with the double click...
Sep 4 '07 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

1
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...
0
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...
2
by: Rob | last post by:
My first GUI so be gentle... When I start my program I call a class that runs the initial window. While in this class if a certain button is pressed it calls a function outside the class. This...
3
by: DoubleM | last post by:
Hi, I'm running Python2.3.3c1 on Mandrake 9.1 The following code is designed to bring up a window with a button labeled "popup". Clicking on the popup buttons triggers a secondary window with...
2
by: Russell E. Owen | last post by:
I want to support execution of simple user-written scripts in a Tkinter application. The scripts should be able to wait for data and such without hanging the GUI (and without having to write the...
1
by: Pekka Niiranen | last post by:
Hi there, after reading TkInter/thread -recipe: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/82965 I wondered if it was possible to avoid using threads for the following problem: ...
6
by: Richard Lewis | last post by:
Hi there, I've got a tree control in Tkinter (using the ESRF Tree module) but I can't get it to layout how I want it. I'd like to have it so that it streches north/south (anchored to the top...
0
by: syed_saqib_ali | last post by:
Below is a simple code snippet showing a Tkinter Window bearing a canvas and 2 connected scrollbars (Vertical & Horizontal). Works fine. When you shrink/resize the window the scrollbars adjust...
0
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...
0
by: Guilherme Polo | last post by:
On Thu, Aug 28, 2008 at 10:29 AM, <dudeja.rajat@gmail.comwrote: It is good to post a short code sample that demonstrates the problem, but it has to run by itself at least. tkMessageBox...
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: 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...
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
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
0
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.