473,698 Members | 1,952 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Please help - Tkinter not doing anything

Hello. I'm a complete newbie trying to learn Python. I decided to try
some Tkinter examples, including the one from the library reference,
but they don't seem to do anything! Shouldn't there be, like, a
dialog?

I'm running Windows XP and using IDLE. You can assume my version of
Python is the latest.
Jun 27 '08 #1
7 3275
Try adding:

from Tkinter import *

at the beginning, and you don't need "var" in front of root=Tk(), just
"root = Tk()" (<-without the quotes of course)
What OS are you on? Are you running "python testapp.py" or similar to
make it run?

-Chuckk

On Sun, May 4, 2008 at 12:39 PM, Protected <pr*******@mysh elter.netwrote:
Good thinking. It was indented with spaces, so I replaced them with tabs.
Now I'm getting a SyntaxError: invalid syntax in root = Tk(). If I split the
code in two parts (with the second one beginning in that line) and run them
separately, I get no errors, but still nothing happens.

class Application(Fra me):
def say_hi(self):
print "hi there, everyone!"

def createWidgets(s elf):
self.QUIT = Button(self)
self.QUIT["text"] = "QUIT"
self.QUIT["fg"] = "red"
self.QUIT["command"] = self.quit

self.QUIT.pack( {"side": "left"})

self.hi_there = Button(self)
self.hi_there["text"] = "Hello",
self.hi_there["command"] = self.say_hi

self.hi_there.p ack({"side": "left"})

def __init__(self, master=None):
Frame.__init__( self, master)
self.pack()
self.createWidg ets()

var root = Tk()
app = Application(mas ter=root)
app.mainloop()
root.destroy()

On Sun, May 4, 2008 at 12:33 PM, Q4 <q4@invalid.com wrote:
On Sun, 4 May 2008 02:23:37 -0700 (PDT), Protected <my*******@gmai l.com>
wrote:
Hello. I'm a complete newbie trying to learn Python. I decided to try
some Tkinter examples, including the one from the library reference,
but they don't seem to do anything! Shouldn't there be, like, a
dialog?
>
I'm running Windows XP and using IDLE. You can assume my version of
Python is the latest.
--
http://mail.python.org/mailman/listinfo/python-list
If you just copy the code from the python doc the indentation might be
broken.
Send the code and I'll take a look at it.

Do you get any errors?

--
My website:
http://www.riddergarn.dk/koder/


--
http://mail.python.org/mailman/listinfo/python-list


--
http://www.badmuthahubbard.com
Jun 27 '08 #2
I had previously ran the import line. I prepended it to the example
code I'm trying to run every time but it did not help, still nothing
happens. With or without var before 'root'. I'm pasting the code in
IDLE and using Windows XP as written in the first post.

On May 4, 11:04 am, "Chuckk Hubbard" <badmuthahubb.. .@gmail.com>
wrote:
Try adding:

from Tkinter import *

at the beginning, and you don't need "var" in front of root=Tk(), just
"root = Tk()" (<-without the quotes of course)
What OS are you on? Are you running "python testapp.py" or similar to
make it run?

-Chuckk

On Sun, May 4, 2008 at 12:39 PM, Protected <protec...@mysh elter.netwrote:
Good thinking. It was indented with spaces, so I replaced them with tabs.
Now I'm getting a SyntaxError: invalid syntax in root = Tk(). If I split the
code in two parts (with the second one beginning in that line) and run them
separately, I get no errors, but still nothing happens.
class Application(Fra me):
def say_hi(self):
print "hi there, everyone!"
def createWidgets(s elf):
self.QUIT = Button(self)
self.QUIT["text"] = "QUIT"
self.QUIT["fg"] = "red"
self.QUIT["command"] = self.quit
self.QUIT.pack( {"side": "left"})
self.hi_there = Button(self)
self.hi_there["text"] = "Hello",
self.hi_there["command"] = self.say_hi
self.hi_there.p ack({"side": "left"})
def __init__(self, master=None):
Frame.__init__( self, master)
self.pack()
self.createWidg ets()
var root = Tk()
app = Application(mas ter=root)
app.mainloop()
root.destroy()
On Sun, May 4, 2008 at 12:33 PM, Q4 <q...@invalid.c omwrote:
On Sun, 4 May 2008 02:23:37 -0700 (PDT), Protected <myshel...@gmai l.com>
wrote:
Hello. I'm a complete newbie trying to learn Python. I decided to try
some Tkinter examples, including the one from the library reference,
but they don't seem to do anything! Shouldn't there be, like, a
dialog?
I'm running Windows XP and using IDLE. You can assume my version of
Python is the latest.
--
http://mail.python.org/mailman/listinfo/python-list
If you just copy the code from the python doc the indentation might be
broken.
Send the code and I'll take a look at it.
Do you get any errors?
--
My website:
http://www.riddergarn.dk/koder/
--
http://mail.python.org/mailman/listinfo/python-list

--http://www.badmuthahub bard.com
Jun 27 '08 #3
On May 4, 5:22 am, Protected <myshel...@gmai l.comwrote:
I had previously ran the import line. I prepended it to the example
code I'm trying to run every time but it did not help, still nothing
happens. With or without var before 'root'. I'm pasting the code in
IDLE and using Windows XP as written in the first post.
Tkinter doesn't work if you type the statements in IDLE. I don't
remember the specifics of it, but essentially it doesn't work because
IDLE is itself a Tkinter app. You have to type it at the Python
command line or save it in a file. BTW, if you're on Windows, you
should definitely check wxPython. I used to work with Tkinter,
struggling with it all the time only to get a lame result most of the
time. Then I switched to wxPython, and in the same week I was learning
it I did a better GUI than I ever did in Tkinter (with months of
work!). I feel it makes it easier to make your program have a better
structure and design, and thus lets you focus on the actual task of
the program, rather than in the GUI itself. Plus, on Windows, you'll
get the widgets to look more natively, like any good quality
application there is on Windows.
Jun 27 '08 #4
On May 4, 12:18 pm, s0s...@gmail.co m wrote:
On May 4, 5:22 am, Protected <myshel...@gmai l.comwrote:
I had previously ran the import line. I prepended it to the example
code I'm trying to run every time but it did not help, still nothing
happens. With or without var before 'root'. I'm pasting the code in
IDLE and using Windows XP as written in the first post.

Tkinter doesn't work if you type the statements in IDLE. I don't
remember the specifics of it, but essentially it doesn't work because
IDLE is itself a Tkinter app. You have to type it at the Python
command line or save it in a file. BTW, if you're on Windows, you
should definitely check wxPython. I used to work with Tkinter,
struggling with it all the time only to get a lame result most of the
time. Then I switched to wxPython, and in the same week I was learning
it I did a better GUI than I ever did in Tkinter (with months of
work!). I feel it makes it easier to make your program have a better
structure and design, and thus lets you focus on the actual task of
the program, rather than in the GUI itself. Plus, on Windows, you'll
get the widgets to look more natively, like any good quality
application there is on Windows.
Ah, but is it cross platform?

(Thanks for letting me know about IDLE.)
Jun 27 '08 #5
WxWidgets, Tkinter, PyQT are all cross platform. Also have a look at
http://wiki.python.org/moin/GuiProgramming
for more GUI frameworks.

RCB
>On May 4, 4:59*am, Protected <myshel...@gmai l.comwrote:
On May 4, 12:18 pm, s0s...@gmail.co m wrote:


On May 4, 5:22 am, Protected <myshel...@gmai l.comwrote:
I had previously ran the import line. I prepended it to the example
code I'm trying to run every time but it did not help, still nothing
happens. With or without var before 'root'. I'm pasting the code in
IDLE and using Windows XP as written in the first post.
Tkinter doesn't work if you type the statements in IDLE. I don't
remember the specifics of it, but essentially it doesn't work because
IDLE is itself a Tkinter app. You have to type it at the Python
command line or save it in a file. BTW, if you're on Windows, you
should definitely check wxPython. I used to work with Tkinter,
struggling with it all the time only to get a lame result most of the
time. Then I switched to wxPython, and in the same week I was learning
it I did a better GUI than I ever did in Tkinter (with months of
work!). I feel it makes it easier to make your program have a better
structure and design, and thus lets you focus on the actual task of
the program, rather than in the GUI itself. Plus, on Windows, you'll
get the widgets to look more natively, like any good quality
application there is on Windows.

Ah, but is it cross platform?

(Thanks for letting me know about IDLE.)- Hide quoted text -

- Show quoted text -
Jun 27 '08 #6
s0****@gmail.co m wrote:
On May 4, 5:22 am, Protected <myshel...@gmai l.comwrote:
>.... I'm pasting the code in IDLE and using Windows XP....

Tkinter doesn't work if you type the statements in IDLE.... it doesn't
work because IDLE is itself a Tkinter app.
Actually, _because_ IDLE is a Tkinter app,you can use it to
experiment with Tkinter in a very useful way. The trick is that
you need to start idle with the "-n" (No subprocesses) switch.
This is so useful that I build a shortcut on my desktop to do exactly
this. Using this shortcut you can see the effect of each action as
you type it, giving you an idea of exactly what must happen.

I'm assuming you are using Python 2.5 here (other versions have
related recipes, but slightly more complicated).
Right click on the desktop, and choose "New Shortcut."

For "Choose the location of the item", browse to (or type in)
C:\Python25\pyt honw.exe
Then (after your next) pick a name for your shortcut.
Right click on the resulting shortcut, and go to "properties "
Change the "Target" entry from:
C:\Python25\pyt honw.exe
to:
C:\Python25\pyt honw.exe -m idlelib.idle -n
Also, if you are like me, you'll want to change the "Start in" directory
to wherever you work on python code --so imports of your own stuff "just
work", and so "File open'" and "Save As" default to a "nice" directory.

The Idle you get with this "corrupts" more easily, since the "-n" says
"no subprocess." Things like restarting the shell don't work. _But_
Tkinter stuff is available (there is already a running mainloop). You
can interactively do simple things a step at a time and watch the
results. It is a _great_ way to experiment with Tkinter.
--Scott David Daniels
Sc***********@A cm.Org

Jun 27 '08 #7
On May 4, 6:59 am, Protected <myshel...@gmai l.comwrote:
On May 4, 12:18 pm, s0s...@gmail.co m wrote:
On May 4, 5:22 am, Protected <myshel...@gmai l.comwrote:
I had previously ran the import line. I prepended it to the example
code I'm trying to run every time but it did not help, still nothing
happens. With or without var before 'root'. I'm pasting the code in
IDLE and using Windows XP as written in the first post.
Tkinter doesn't work if you type the statements in IDLE. I don't
remember the specifics of it, but essentially it doesn't work because
IDLE is itself a Tkinter app. You have to type it at the Python
command line or save it in a file. BTW, if you're on Windows, you
should definitely check wxPython. I used to work with Tkinter,
struggling with it all the time only to get a lame result most of the
time. Then I switched to wxPython, and in the same week I was learning
it I did a better GUI than I ever did in Tkinter (with months of
work!). I feel it makes it easier to make your program have a better
structure and design, and thus lets you focus on the actual task of
the program, rather than in the GUI itself. Plus, on Windows, you'll
get the widgets to look more natively, like any good quality
application there is on Windows.

Ah, but is it cross platform?

(Thanks for letting me know about IDLE.)
Of course. I forgot to say about that. It is cross platform, like most
things in Python. I'd say it's actually more cross platform than
Tkinter, because of the looks of both in different platforms. In
Tkinter, you can get all the widgets to work in all the platforms it
supports, but the widgets look so different on different platforms,
that at the end you end up modifying the code anyway so that the
controls look better on the platform that you port the program to.
With what I've done with wxPython, the controls look great on any of
the platforms I've tried my programs in. Another thing: wxPython is a
port of the wxWidgets toolkit which is for C++. It has also been
ported to a bunch of other languages like Ruby, Perl, C#, etc; so if
you learn any of the languages which wxWidgets has been ported to, you
can use the toolkit in the same way that you've been doing with
Python, except that with the syntax of the other language.
Jun 27 '08 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
7198
by: Andrew Gregory | last post by:
Could someone help me out with these few lines of code: I would like to know why the Quit button in this application removes the buttons and causes "Quitting" to be printed, but does not close the outer frame. Andrew. # Demonstration TK interface Windows application # Runs ok from within IDLE
3
7030
by: srijit | last post by:
Hello, Any idea - why the following code crashes on my Win 98 machine with Python 2.3? Everytime I run this code, I have to reboot my machine. I also have Win32all-157 installed. from Tkinter import * class App:
5
4759
by: carljohan.rehn | last post by:
I would like like to start doing some GUI-programming in Python, but don't know which library to choose. Tkinter seems a bit old. Correct me if I am wrong! The layout doesn't look as nice as for the others. wxPython seems to be the first-hand choice for people doing W32-programming (with MFC-experience). PyGtk seems to be a modern, very clean and nice approach, but with poor
5
2053
by: max(01)* | last post by:
hello. the following code: 1 from Tkinter import * 2 3 class MiaApp: 4 def __init__(self, genitore): 5 self.mioGenitore = genitore 6 self.i = IntVar()
6
8250
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):
5
3559
by: Ben Kovitz | last post by:
Hi, I just tried to run Tkinter on OS X 10.3.9 under Python 2.4.3, and I'm getting a bus error as soon as I call Tk(). Googling has turned up info other Tkinter bus errors, but not this one that occurs right away, before doing anything fancy. Tk/Tcl is definitely installed on my computer, as verified by running "wish" and seeing the window come up. "info patchlevel" returns 8.4.5. Here's the tail of the output from python -v:
4
2105
by: Chris | last post by:
Hi, I'm puzzled by some strange behavior when my Python/Tkinter application quits (on linux): the terminal from which I started Python is messed up. If start up python, then import the code below, then start the program with Application(), then click the Quit button, my terminal never prints anything again (such as commands I type).
44
4989
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 processed by this script, where the concerned tmp file is only actually written to when PythonWin is closed. In other words, after I run this script, one of the generated tmp files has a size of 0kB. I then close PythonWin and it is then written to.
0
1541
by: wolfonenet | last post by:
Hi All, My setup is: WinXP Python 2.5.1 TKinter version: $Revision: 50704 $ Tcl: 8.4 Debugger: WinPdb
0
8598
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
9152
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8856
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
6515
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
5858
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
4360
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4613
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3037
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
3
1997
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.