[Tutor] Tkinter problems
alan.gauld@bt.com
alan.gauld@bt.com
Sun, 7 Apr 2002 22:55:11 +0100
------_=_NextPart_001_01C1DE7E.E3B28E60
Content-type: text/plain; charset="ISO-8859-1"
> working on getting buttons with Tkinter, but I can't. I get the Tkinter
window
> to open up when I run the code, but the button(s) won't show up.
I suspect you've forgoptten to pack the buttons.
You create them as widgets but before they show up you have
to pack() them(or place() them or grod() them)
But without any sample code its kind of hard to be sure...
This should work to test my theory:
>>> from Tkinter import *
>>> tk = Tk() # window appears
>>> b = Button(text = "Hello") # create button widget
>>> b.pack() # button widget appears
>>> tk.mainloop() # run the GUI, quit via titlebar icon
See my tutor's intro to Tkinter for more on this
> IDLE doesn't show any errors.
I really recommend not running Tkinter programs from
within IDLE. I know there are workarounds (like not
calling mainloop() ) but I find it much better to use
IDLE as an editor if you must but run the programs
from an OS prompt.
Alan g.
Author of the 'Learning to Program' web site
http://www.freenetpages.co.uk/hp/alan.gauld
<http://www.freenetpages.co.uk/hp/alan.gauld>
------_=_NextPart_001_01C1DE7E.E3B28E60
Content-type: text/html; charset="ISO-8859-1"
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=ISO-8859-1">
<META content="MSHTML 5.50.4807.2300" name=GENERATOR></HEAD>
<BODY>
<DIV><SPAN class=380514921-07042002><FONT face="Courier New" color=#0000ff
size=2>> </FONT></SPAN>working on getting buttons with Tkinter, but I
can't. I get the Tkinter window <SPAN class=380514921-07042002><FONT
face="Courier New" color=#0000ff size=2> </FONT></SPAN></DIV>
<DIV><SPAN class=380514921-07042002><FONT face="Courier New" color=#0000ff
size=2>> </FONT> </SPAN>to open up when I run the code, but the
button(s) won't show up. <SPAN class=380514921-07042002><FONT
face="Courier New" color=#0000ff size=2> </FONT></SPAN></DIV>
<DIV><SPAN class=380514921-07042002><FONT face="Courier New" color=#0000ff
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=380514921-07042002><FONT face="Courier New" color=#0000ff
size=2>I suspect you've forgoptten to pack the buttons.</FONT></SPAN></DIV>
<DIV><SPAN class=380514921-07042002><FONT face="Courier New" color=#0000ff
size=2>You create them as widgets but before they show up you have
</FONT></SPAN></DIV>
<DIV><SPAN class=380514921-07042002><FONT face="Courier New" color=#0000ff
size=2>to pack() them(or place() them or grod() them)</FONT></SPAN></DIV>
<DIV><SPAN class=380514921-07042002><FONT face="Courier New" color=#0000ff
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=380514921-07042002><FONT face="Courier New" color=#0000ff
size=2>But without any sample code its kind of hard to be
sure...</FONT></SPAN></DIV>
<DIV><SPAN class=380514921-07042002><FONT face="Courier New" color=#0000ff
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=380514921-07042002><FONT face="Courier New" color=#0000ff
size=2>This should work to test my theory:</FONT></SPAN></DIV>
<DIV><SPAN class=380514921-07042002><FONT face="Courier New" color=#0000ff
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=380514921-07042002><FONT face="Courier New" color=#0000ff
size=2>>>> from Tkinter import *</FONT></SPAN></DIV>
<DIV><SPAN class=380514921-07042002><FONT face="Courier New" color=#0000ff
size=2>>>> tk = Tk() # window appears</FONT></SPAN></DIV>
<DIV><SPAN class=380514921-07042002><FONT face="Courier New" color=#0000ff
size=2>>>> b = Button(text = "Hello") # create button
widget</FONT></SPAN></DIV>
<DIV><SPAN class=380514921-07042002><FONT face="Courier New" color=#0000ff
size=2>>>> b.pack() # button widget
appears</FONT></SPAN></DIV>
<DIV><SPAN class=380514921-07042002><FONT face="Courier New" color=#0000ff
size=2>>>> tk.mainloop() # run the GUI, quit via titlebar
icon</FONT></SPAN></DIV>
<DIV><SPAN class=380514921-07042002><FONT face="Courier New" color=#0000ff
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=380514921-07042002><FONT face="Courier New" color=#0000ff
size=2>See my tutor's intro to Tkinter for more on this</FONT></SPAN></DIV>
<DIV><SPAN class=380514921-07042002></SPAN><SPAN
class=380514921-07042002></SPAN><SPAN class=380514921-07042002></SPAN><SPAN
class=380514921-07042002><FONT face="Courier New" color=#0000ff
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=380514921-07042002><FONT face="Courier New" color=#0000ff
size=2>> </FONT> </SPAN>IDLE doesn't show any errors. <SPAN
class=380514921-07042002><FONT face="Courier New" color=#0000ff
size=2> </FONT></SPAN></DIV>
<DIV><SPAN class=380514921-07042002><FONT face="Courier New" color=#0000ff
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=380514921-07042002><FONT face="Courier New" color=#0000ff
size=2>I really recommend not running Tkinter programs from </FONT></SPAN></DIV>
<DIV><SPAN class=380514921-07042002><FONT face="Courier New" color=#0000ff
size=2>within IDLE. I know there are workarounds (like not </FONT></SPAN></DIV>
<DIV><SPAN class=380514921-07042002><FONT face="Courier New" color=#0000ff
size=2>calling mainloop() ) but I find it much better to use
</FONT></SPAN></DIV>
<DIV><SPAN class=380514921-07042002><FONT face="Courier New" color=#0000ff
size=2>IDLE as an editor if you must but run the programs </FONT></SPAN></DIV>
<DIV><SPAN class=380514921-07042002><FONT face="Courier New" color=#0000ff
size=2>from an OS prompt.</FONT></SPAN></DIV>
<DIV><SPAN class=380514921-07042002><FONT face="Courier New" color=#0000ff
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=380514921-07042002><FONT face="Courier New" color=#0000ff
size=2>
<P><FONT size=2>Alan g.<BR>Author of the 'Learning to Program' web site<BR><A
target=_blank
href="http://www.freenetpages.co.uk/hp/alan.gauld">http://www.freenetpages.co.uk/hp/alan.gauld</A></FONT>
</P></FONT></SPAN><SPAN class=380514921-07042002><FONT face="Courier New"
color=#0000ff size=2></FONT></SPAN></DIV>
<DIV><FONT face="Courier New" color=#0000ff
size=2></FONT> </DIV></BODY></HTML>
------_=_NextPart_001_01C1DE7E.E3B28E60--