473,218 Members | 1,673 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,218 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 4716
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...
1
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
0
by: veera ravala | last post by:
ServiceNow is a powerful cloud-based platform that offers a wide range of services to help organizations manage their workflows, operations, and IT services more efficiently. At its core, ServiceNow...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
2
by: jimatqsi | last post by:
The boss wants the word "CONFIDENTIAL" overlaying certain reports. He wants it large, slanted across the page, on every page, very light gray, outlined letters, not block letters. I thought Word Art...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....

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.