Presentation is loading. Please wait.

Presentation is loading. Please wait.

Lesson 3 - The Entry Box.. Last week We produced a Tkinter window with a label and a button Now we are going to create a new program that creates a Button.

Similar presentations


Presentation on theme: "Lesson 3 - The Entry Box.. Last week We produced a Tkinter window with a label and a button Now we are going to create a new program that creates a Button."— Presentation transcript:

1 Lesson 3 - The Entry Box.

2 Last week We produced a Tkinter window with a label and a button Now we are going to create a new program that creates a Button and an Entry Box. The user writes in the box. When the button is pressed that input is made into a new label To do this we must write or define a function And then call (execute) that function when the button is pressed

3 The New Program Open Python Then go File > New window In the new untitled window Go File > Save As Save the file tkentry.py in your area

4 import sys from tkinter import * mGui = Tk() mGui.geometry (‘400 x400’) mGui.title(‘My Window’) mlabel=Label(text=‘Testwood School’).pack() mbutton=Button(mGui,text=“OK”).pack() mGui.mainloop()

5 First lets create the Entry Box – underneath the label Testwood School import sys from tkinter import* mGui = Tk() ment = Stringvar() mGui.geometry (‘400 x400’) mGui.title(‘My Window’) mlabel=Label(text=‘Testwood School’).pack() mEntry = Entry(mGui,textvariable = ment).pack() mbutton=Button(mGui,text=“OK”).pack() mGui.mainloop() # ment is a variable which stores what is typed in the entry box

6 Now lets write our function. import sys from tkinter import* def myinput(): mtext = ment.get() mlabel2= Label(mGui,text=mtext).pack() mGui = Tk() mGui.geometry (‘400 x400’) mGui.title(‘My Window’) mlabel=Label(text=‘Testwood School’).pack() mEntry = Entry(mGui,textvariable = ment).pack() mbutton=Button(mGui,text=“OK”).pack() mGui.mainloop() # ment is a variable which stores what is typed in the entry box

7 And finally lets get the button to call (execute) the function. import sys from tkinter import* def myinput(): mtext = ment.get() mlabel2= Label(mGui,text=mtext).pack() mGui = Tk() mGui.geometry (‘400 x400’) mGui.title(‘My Window’) mlabel=Label(text=‘Testwood School’).pack() mEntry = Entry(mGui,textvariable = ment).pack() mbutton=Button(mGui,text=“OK”,command=myinput).pack() mGui.mainloop() # ment is a variable which stores what is typed in the entry box

8 Extension Task – Try this code what’s changed and why? import sys from tkinter import* def mentry(): mtext=ment.get() ytext=yent.get() mlabel2=Label(mGui,text=mtext+ytext).pack() mGui =Tk() ment=IntVar() yent=IntVar() mGui.geometry("450x450+200+200") mGui.title ("Testwood Calculator") mlabel=Label(mGui,text="Testwood Calculator").pack() mEntry=Entry(mGui,textvariable=ment,width=5).pack() yEntry=Entry(mGui,textvariable=yent).pack() mbutton=Button(mGui,text="OK",command=mentry).pack() mGui.mainloop()

9 Next week we will create a canvas and place an image in our window.


Download ppt "Lesson 3 - The Entry Box.. Last week We produced a Tkinter window with a label and a button Now we are going to create a new program that creates a Button."

Similar presentations


Ads by Google