<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
<title></title>
</head>
<body bgcolor="#ffffff" text="#000000">
Dan Deternova napsal(a):
<blockquote cite="mid9560d3c05080816487b0b46c2@mail.gmail.com"
type="cite">i am making a simple script to get the hang of Tkinter. i
want to use the input of the user from a Entry and calcuate the area. i
have tryied many way... as you can see in my script. the Entry is
under def area(): and the output i want is under def cal(): ...
please help me fix my code and explain to me what you did.. thanks in
advance.
<br clear="all">
<br>
<a href="mailto:%7Emoparfan90@gmail.com"></a></blockquote>
here is corrected script, I just correct the area funciton and all what
belongs to it. Instead of DoubleVar, you could also use IntVar, if you
prefer....<br>
<br>
<tt>#program made and maintained by Dan Deternova<br>
#start of program<br>
<br>
from Tkinter import
*
# tells computer we are using Tkinter modual<br>
from tkMessageBox import *<br>
def cal():<br>
win4 = Toplevel<br>
print 'area = ', w.get()*h.get()<br>
<br>
def notyet():<br>
showerror('not yet avalable')<br>
<br>
win =
Tk()
# makes windows and has value for Tk<br>
def makemenu(Tk):<br>
top = Menu(win)<br>
win.config(menu=top)<br>
<br>
file = Menu(top)<br>
file.add_command(label='save your name', command=newwin,
underline=0)<br>
file.add_command(label='quit', command=win.destroy, underline=0)<br>
file.add_command(label='quit all', command=win.quit, underline=0)<br>
top.add_cascade(label='file', menu=file, underline=0)<br>
edit = Menu(top, tearoff=0)<br>
edit.add_command(label='copy', command=notyet, underline=0)<br>
edit.add_command(label='paste', command=notyet, underline=0)<br>
edit.add_command(label='quit', command=win.destroy, underline=0)<br>
top.add_cascade(label='edit', menu=edit, underline=0)<br>
<br>
<br>
def
newwin():
# callback to define button newwin.<br>
win2 =
Toplevel()
# makes new window when button is pressed. named win2<br>
widget = Label(win2, text='your name
here').pack() # line 'type your
name here' is printed on top of entry<br>
name = StringVar()<br>
widget = Entry(win2,
textvariable=name).pack() #
makes entry in new window at the top.<br>
widget = Label(win2, text='age
here').pack() # prints the
line 'age here'<br>
age = StringVar()<br>
widget = Entry(win2,
textvariable=age).pack() #
makes entry<br>
widget = Label(win2, text='type your address here').pack()<br>
address = StringVar()<br>
widget = Entry(win2, textvariable=address).pack()<br>
def save():<br>
f=file('fname','a')<br>
f.write(name.get()+'\n')<br>
f.write(age.get()+'\n')<br>
f.write(address.get()+'\n')<br>
<br>
widget = Button(win2, text='save', command=save).pack(side=LEFT)<br>
widget = Button(win2, text='quit',
command=win2.destroy).pack(side=RIGHT)<br>
def area():<br>
global w,h<br>
win3 = Toplevel()<br>
widget = Label(win3, text='type hieght here: ').pack()<br>
h = DoubleVar()<br>
widget = Entry(win3, textvariable=h).pack()<br>
widget = Label(win3, text='type width here: ').pack()<br>
w = DoubleVar()<br>
widget = Entry(win3, textvariable=w).pack()<br>
widget = Button(win3, text=' calculate ',
command=cal).pack(side=BOTTOM, expand=YES, fill=BOTH)<br>
<br>
<br>
fontentry = ('times', 20,
'bold') #
(font, size, style) defonision for fontentry. will be used later on in
the program<br>
widget = Entry(win, text='type
here') # makes
entry point in 'win'<br>
makemenu(win)<br>
widget.config(font=fontentry)
# makes the font of entry equal to 'fontentry'<br>
widget.config(bg='blue',
fg='yellow') #
makes the background (bg) black and the forground (text) yellow<br>
widget.pack(side=TOP, expand=YES,
fill=BOTH) # 'packs' the
entry on top of win and expands and fill the Y axes<br>
widget = Button(win, text="your name", command=newwin).pack(side=LEFT,
expand=YES, fill=BOTH)# creates button that says 'your name'. see
newwin callback for output.<br>
widget = Button(win, text='quit all',
command=win.quit).pack(side=BOTTOM, expand=YES, fill=BOTH)<br>
widget = Button(win, text='quit', command=win.destroy).pack(side=RIGHT,
expand=YES, fill=BOTH)<br>
widget = Button(win, text='area', command=area).pack(side=LEFT,
expand=YES, fill=BOTH)<br>
win.title('my program')<br>
<br>
#end of program<br>
<br>
</tt>
<pre class="moz-signature" cols="100"><tt>-- </tt>
geon
</pre>
</body>
</html>