BenWoodfieldraserppsprograms@gmail.
comTkinterGUIBasics
Example4:TkinterGUIWindow/TextEntry
Inthisexample,[Link]
[Link],Irecommendchangingthecolours,orfontsizes
[Link].
[Link],butwehavegonea
[Link],andwhenthebuttonispressedthewrittentextgets
printedintheShellwindow.
Heresthenewcode:
from tkinter import *
top = Tk()
[Link]('Tkinter GUI - Example 4')
[Link](400, 400)
[Link](bg='orange')
lbl = Label(top, text='Assigning Functions To Buttons', bg='yellow', fg='blue', font='14')
[Link]()
def hello_callback(): print('Button Clicked')
def callback():
print([Link]())
btn = Button(top, text='Click Here', font='freesansbold, 14', command=hello_callback)
[Link]()
exit_button=Button(top, text='Exit', fg='red', bg='black', font='freesansbold, 14', command=quit)
exit_button.pack(side=BOTTOM)
ent = Entry(top)
[Link]()
btn2 = Button(top, text='Print Text', fg='blue', font='bold, 14', width=15, command=callback)
[Link]()
[Link]()
Sowehaveaddedanewfunction:
def callback()
Thenewfunctionhasalinereading print([Link]()) WhichtellsPythonto'Get'thestringthatis
enteredintheentrybox,and'print'[Link]
functionlikethis,wecanassignitasacommandtoabutton(ourclickherebutton)
Againafewvisualdetailshavemayhavebeenalteredbutbynowyoushouldbeabletochangethese
yourselfasit'snothingwehaven'tcoveredalready.
Inthenextexamplewewillrewriteanexistingprogramofminethattakesuserinput,performsacalculation
withit,thengivesitbacktotheuserbydisplayingitintheGUIItisaFeettoMetersconverterapp/
program.