473,657 Members | 2,550 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Tkinter root window problem

rhitam30111985
112 New Member
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=askstrin g('site','enter site:')
File "/usr/lib/python2.4/lib-tk/tkSimpleDialog. py", line 304, in askstring
d = _QueryString(ti tle, 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._defaul t_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 4753
bartonc
6,596 Recognized Expert Expert
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 New Member
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 Recognized Expert Expert
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 New Member
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 Recognized Expert Expert
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 New Member
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 New Member
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 New Member
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
5968
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 filling the remainder of the window. Mind you, this is a contrived test application to help me understand Tkinter and Python, not an actual application yet. I've trivially subclassed Tkinter.Canvas into ColorCanvas, added a bunch of ColorCanvases...
0
3066
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 the context of a main window. The problem does not occur on HPUX or Linux. The following simple example code illustrates the problem and the work around I've come up with; However, I'd like, very much, to get rid of the kludgy work around....
2
26232
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 function then initially calls another function to "root.destroy()". Basically I want the current window gone so the function I just called can open it's own window. The problem I'm stuck with is that once this function is done and I need to close...
3
3332
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 a button labeled "ok". The second window is supposed to be modal - it should not be possible to reset the focus back to the first window or close the first window without first closing the second. The program works just fine in Windows XP...
2
3877
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 script as a bunch of asynchronously called subroutines). I decided to use Tkinter's wait_variable. I built a "script runner" object that has suitable wait methods. Internally each of these methods registers a callback that sets a variable when...
1
2243
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: I have script started from W2K console that normally prints ascii messages to the screen. However, I have command line "debug" -flag that might cause printing
6
8247
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 and bottom), is of a fixed width and is anchored to the left hand side. Here's my code (its derived from one of the examples from the ESRF web site):
0
3578
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 accordingly. However, what I really want to happen is that the area of the canvas that the scrollbars show (the Scrollregion) should expand as the window grows. It doesn't currently do this. although, if the window shrinks smaller than the...
0
2348
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 widget, but for some reason the text is invisible on cygwin). After I close the Toplevel widget, all of the menus in my app behave as though they have no contents to them, i..e I can press on the File menu button, and see it depress, but the Exit...
0
1758
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 blocks till you finish it, maybe that is what is causing your problem but it is hard to tell what you are doing wrong in that myAppGui without seeing it (preferably reduced code demonstrating the problem).
0
8326
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8743
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8622
tracyyun
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6177
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5647
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4333
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2745
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1973
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1736
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.