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

TkInter displays extra windows after winfo is called.

Expand|Select|Wrap|Line Numbers
  1. #! /usr/bin/python
  2. # This one creates three windows because of the Tk().winfo_screenwidth(),
  3. # Tk().winfo_screenheight() call
  4.  
  5. from Tkinter import *
  6.  
  7. def quit(): sys.exit(0)
  8.  
  9. root = Tk()
  10. root.title("Test screen")
  11. w, h = Tk().winfo_screenwidth(), Tk().winfo_screenheight()
  12. h = h * 0.75
  13. paper = Canvas(root, width = h, height = h, bg = "#000020")
  14.  
  15. a = h / 10
  16. b = h - a
  17.  
  18. paper.create_line(a, a, b, b, fill="white")
  19. paper.create_line(a, b, b, a, fill="white")
  20.  
  21. exitB = Button(text="Exit", width=15, command=quit)
  22. exitB.pack()
  23.  
  24. paper.pack()
  25. mainloop()
  26.  
Expand|Select|Wrap|Line Numbers
  1. #! /usr/bin/python
  2. # This one creates only a single window.
  3.  
  4. from Tkinter import *
  5.  
  6. def quit(): sys.exit(0)
  7.  
  8. root = Tk()
  9. root.title("Test screen")
  10.  
  11. h = 400
  12. paper = Canvas(root, width = h, height = h, bg = "#000020")
  13.  
  14. a = h / 10
  15. b = h - a
  16.  
  17. paper.create_line(a, a, b, b, fill="white")
  18. paper.create_line(a, b, b, a, fill="white")
  19.  
  20. exitB = Button(text="Exit", width=15, command=quit)
  21. exitB.pack()
  22.  
  23. paper.pack()
  24. mainloop()
  25.  
Any idea how to easily fix this? Thanks in advance...

Greg
Aug 28 '10 #1

✓ answered by bvdet

Gregory,

Since you have gotten your answer, please mark the appropriate post with the 'choose as best answer button'. This makes it easier for the next person to find the solution.

3 2770
dwblas
626 Expert 512MB
You are starting 3 instances of Tk(). Use root instead
Expand|Select|Wrap|Line Numbers
  1. ##--- instance 1
  2. root = Tk()
  3. root.title("Test screen")
  4.  
  5. ##-- instances 2 & 3
  6. w, h = Tk().winfo_screenwidth(), Tk().winfo_screenheight()
  7.  
  8. """ this opens one window only
  9. ""
  10. root = Tk()
  11. root.title("Test screen")
  12. w, h = root.winfo_screenwidth(), root.winfo_screenheight() 
Also, to exit, use the quit command instead of sys.exit.
Expand|Select|Wrap|Line Numbers
  1. exitB = Button(text="Exit", width=15, command=root.quit)
Aug 28 '10 #2
Like most errors, this one is trivial when solved, but opaque beforehand. Many thanks, dwblas!
Aug 29 '10 #3
bvdet
2,851 Expert Mod 2GB
Gregory,

Since you have gotten your answer, please mark the appropriate post with the 'choose as best answer button'. This makes it easier for the next person to find the solution.
Sep 4 '10 #4

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

Similar topics

4
by: Tom Locke | last post by:
Hi All, I'm having trouble with the python shell within emacs. It's hanging when I use tkinter. Setup is: Windows XP emacs 21.3 py-mode 4.6 Recipe:
0
by: Todd Miller | last post by:
I'm working on a Tkinter backend for the matplotlib plotting software. matplotlib can be run interactively from some form of Python shell while plotting to a Tk window. One annoyance we've noticed...
1
by: corrado | last post by:
Hello I have an application running several thread to display some financial data; basically I have a thread displaying HTML tables by means of Tkhtml, another implementing a scrolling ticker...
0
by: Dan Greenblatt | last post by:
I am trying to programmatically manipulate the menus in my application, for purposes of a tutorial, showing users where things are in our application's menu interface. My goal is to be able to...
0
by: John Fouhy | last post by:
Hi all, I have been attempting to change the title bar icon of my Tkinter applications in Windows XP. Chasing round in google, I discovered: - This is a common difficulty. - There aren't any...
1
by: Tim Daneliuk | last post by:
Arrrrrggg. I have a program that runs comfortably across both Unix variants and Windows ... except .... I wish to bind an Alt-ButtonRelease-3 combination to popup a menu. This works flawlessly...
7
by: krishnakant Mane | last post by:
hello all, I seam to have noticed this a bit late but it appears to me that tkinter is being used very widely for gui development on all platform? is that right? since fredric lundh has written a...
0
by: psbasha | last post by:
Hi, How to find the Tkinter module is available in Windows and UNIX OS or not?. Is there any command available? Thanks PSB
44
by: bg_ie | last post by:
Hi, I'm in the process of writing some code and noticed a strange problem while doing so. I'm working with PythonWin 210 built for Python 2.5. I noticed the problem for the last py file...
1
by: akineko | last post by:
Hello everyone, I'm trying to create custom Tkinter/Pmw widgets for my project. After testing my widgets under Unix (Solaris), I have tried them under Windows and I got a surprise. The...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...

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.