[Tutor] embarrassingly basic Tkinter question...

Michael Lange klappnase at freenet.de
Mon Jun 28 06:06:34 EDT 2004


On Sun, 27 Jun 2004 22:13:31 -0400
Marv Boyes <marvboyes at att.net> wrote:


> Here's what I have so far:
> 
> 	from Tkinter import *
> 	from os import system   # now what?
> 
> 	root = Tk()
> 	root.title("Melody's Internet Stuff")
> 	root.geometry("280x150")
> 	app = Frame(root)
> 	app.grid()
> 
> 	bttn1 = Button(app, text = "Connect to the Internet")
> 	bttn1.grid()
> 
> 	bttn2 = Button(app, text = "Get, read, and write e-mail")
> 	bttn2.grid()
> 
> 	bttn3 = Button(app, text = "Browse the Web")
> 	bttn3.grid()
> 
> 	bttn4 = Button(app, text = "Close",command = 'exit')
> 	bttn4.grid()
> 
> 	root.mainloop()
> 
> Now, what I want to do is launch an application by pressing buttons 1, 
> 2, or 3. I'm guessing that the os module is involved, but I found that a 
> simple command = system('appname') launched the application as soon as I 
> ran the Python script; indeed, my Tk window wouldn't even appear until 
> that application was closed. So I'm obviously missing something.
> 

Probably you did something like:

os.system('mozilla')

within your code and as you told python it launched the browser and then waited until the system command had finished.
If you want to run programs in the background use

os.system('mozilla &')

The second problem is that you of course don't want the program to be started with your app, but just
when the corresponding button is pressed. To achieve this you have to define a function for
each button callback, like this:

def browse_the_web():
    os.system('mozilla &')

(...)

bttn3 = Button(app, text = "Browse the Web", command=browse_the_web)
(...)

I hope this helped

Michael



More information about the Tutor mailing list