[Tutor] newbie:Problem with arguments for methods
Christopher Abrams
dreamz39@yahoo.com
Sun, 21 Jan 2001 07:02:09 -0800 (PST)
--0-1540383426-980089329=:15969
Content-Type: text/plain; charset=us-ascii
Python is my first programming language and I made a small change to a script on the Intro to Tkinter page:
# File: hello2.py
from Tkinter import *
class App:
def __init__(self, master):
frame = Frame(master)
frame.pack()
self.button = Button(frame, text="QUIT", fg="red", command=frame.quit)
self.button.pack(side=LEFT)
self.hi_there = Button(frame, text="Hello", command=self.say_hi)
self.hi_there.pack(side=LEFT)
def say_hi(self):
print "hi there, everyone!"
root = Tk()
app = App(root)
root.mainloop()
was chaged to:
from Tkinter import *
import Image
class App:
def __init__(self, master):
frame = Frame(master)
frame.pack()
self.viewer = Canvas(frame)
self.viewer.pack(side=BOTTOM)
self.button = Button(frame, text="QUIT", fg="red", activebackground = "black", activeforeground = "yellow",command=frame.quit)
self.button.pack(side=LEFT)
self.hi_there = Button(frame, bitmap = "info", relief="raised", command=self.say_hi(self.viewer))
self.hi_there.pack(side=LEFT)
def say_hi(self, canv):
canv.create_oval(10,20,50,60)
root = Tk()
app = App(root)
root.mainloop()
Before the small changes the button would write "print this" to the console for each click of the button.The changes were made only to play around with Tkinter a little, but when I add the argument to self.say_hi it doesn't wait for me to press the button. It just runs straight through as if the has already been called. I am sure I must not understand something. Please help. Also how do I display images(.bmp, .jpg, .gif) on a Tkinter canvas.
Thanks,
C. Abrams
---------------------------------
Do You Yahoo!?
Yahoo! Auctions - Buy the things you want at great prices.
--0-1540383426-980089329=:15969
Content-Type: text/html; charset=us-ascii
<P>Python is my first programming language and I made a small change to a script on the Intro to Tkinter page:</P>
<P># File: hello2.py<BR><BR>from Tkinter import *<BR><BR>class App:<BR><BR> def __init__(self, master):<BR><BR> frame = Frame(master)<BR> frame.pack()<BR><BR> self.button = Button(frame, text="QUIT", fg="red", command=frame.quit)<BR> self.button.pack(side=LEFT)<BR><BR> self.hi_there = Button(frame, text="Hello", command=self.say_hi)<BR> self.hi_there.pack(side=LEFT)<BR><BR> def say_hi(self):<BR> print "hi there, everyone!"<BR><BR>root = Tk()<BR><BR>app = App(root)<BR><BR>root.mainloop()</P>
<P> </P>
<P>was chaged to:</P>
<DIR><FONT color=#000000 size=2>
<P>from Tkinter import *</P>
<P>import Image</P>
<P>class App:</P>
<P>def __init__(self, master):</P>
<P></P>
<P>frame = Frame(master)</P>
<P>frame.pack()</P>
<P></P>
<P>self.viewer = Canvas(frame)</P>
<P>self.viewer.pack(side=BOTTOM)</P>
<P></P>
<P>self.button = Button(frame, text="QUIT", fg="red", activebackground = "black", activeforeground = "yellow",command=frame.quit)</P>
<P>self.button.pack(side=LEFT)</P>
<P></P>
<P>self.hi_there = Button(frame, bitmap = "info", relief="raised", command=self.say_hi(<STRONG>self.viewer</STRONG>))</P>
<P>self.hi_there.pack(side=LEFT)</P>
<P></P>
<P>def say_hi(self, <STRONG>canv</STRONG>): </P>
<P><STRONG>canv.create_oval(10,20,50,60)</STRONG></P>
<P></P>
<P></P>
<P>root = Tk()</P>
<P>app = App(root)</P></DIR>
<P>root.mainloop()</P>
<P> </P>
<P>Before the small changes the button would write "print this" to the console for each click of the button.The changes were made only to play around with Tkinter a little, but when I add the argument to self.say_hi it doesn't wait for me to press the button. It just runs straight through as if the has already been called. I am sure I must not understand something. Please help. Also how do I display images(.bmp, .jpg, .gif) on a Tkinter canvas. </P>
<P>Thanks,</P>
<P>C. Abrams</P></FONT>
<P> </P><p><br><hr size=1><b>Do You Yahoo!?</b><br>
<a href=http://auctions.yahoo.com/>Yahoo! Auctions</a> - Buy the things you want at great prices.
--0-1540383426-980089329=:15969--