471,338 Members | 1,377 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,338 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 4493
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

Post your reply

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

Similar topics

reply views Thread by Bruce Davis | last post: by
2 posts views Thread by Rob | last post: by
3 posts views Thread by DoubleM | last post: by
2 posts views Thread by Russell E. Owen | last post: by
1 post views Thread by Pekka Niiranen | last post: by
6 posts views Thread by Richard Lewis | last post: by
reply views Thread by syed_saqib_ali | last post: by
reply views Thread by Stewart Midwinter | last post: by

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.