[Tutor] 2 quick questions on python/tkinter

Ray Leggett rlegge@tc3net.com
Sat, 21 Sep 2002 21:37:16 -0400


Ok, i wrote this little demo app on windows, but included the #!/bin/pyth=
on=20
line so i could work on it under linux, too:

-------------------------------------------------------------------------=
-----------------------------
#!/usr/bin/python

# File: widgets.pyw

# gives basic examples of tkinter widgets

from Tkinter import *

# create a class to handle the gui

class Application(Frame):
=09def __init__(self, master=3DNone):  # creates the root window
=09=09Frame.__init__(self, master)
=09=09self.grid()
=09=09self.createWidgets()
=09def createWidgets(self):=09# creates the child widgets
=09=09self.label =3D Label( self, text =3D "Label!")
=09=09self.label.grid()
=09=09self.chkbox =3D Checkbutton(self, text =3D "Check Button")
=09=09self.chkbox.grid()
=09=09self.entry =3D Entry(self)
=09=09self.entry.grid()
=09=09self.message =3D Message(self, text =3D "Message!")
=09=09self.message.grid()
=09=09self.quitButton =3D Button ( self, text=3D"Quit",command=3Dself.qui=
t )
=09=09self.quitButton.grid()
=09=09

app =3D Application() # Instantiate the application class
app.master.title("Widget Examples")
app.mainloop() # Wait for events

-------------------------------------------------------------------------=
-----------------------------

It runs fine under windows, but under linux it gave the following error:

bash: ./widgets2.py: bad interpreter: No such file or directory

Oddly, it runs fine when i type python widgets2.py.  Whats going on?

My second question -  you see the self.widget.grid()  line repeated sever=
al=20
times in the Application class.  Is there some way i can apply the grid()=
=20
function once to to all of the widgets?