[Tutor] GUI program
Nick
nickli.1540489 at gmail.com
Sat Apr 4 16:14:13 EDT 2020
You can try this code:
import tkinter
class MyGUI:
def __init__(self):
self.main_window = tkinter.Tk()
# Creates the frames
self.top_frame = tkinter.Frame(self.main_window)
self.bottom_frame = tkinter.Frame(self.main_window)
# StringVar object to display in Label
self.texta = tkinter.StringVar()
self.textb = tkinter.StringVar()
self.textc = tkinter.StringVar()
# Creating the label and associate it with the StringVar object
above
self.name_label = tkinter.Label(self.top_frame, textvariable =
self.texta)
self.street_label = tkinter.Label(self.top_frame, textvariable =
self.textb)
self.state_label = tkinter.Label(self.top_frame, textvariable =
self.textc)
self.my_button = tkinter.Button(self.bottom_frame, text = 'Show
Info', command = self.do_something)
self.quit_button = tkinter.Button(self.bottom_frame, text =
'Quit', command = self.main_window.destroy)
# Packing the Labels from top to bottom
self.name_label.pack(side = 'top')
self.street_label.pack(side = 'top')
self.state_label.pack(side = 'top')
# Packing the Buttons from left to right
self.my_button.pack(side = 'left')
self. quit_button.pack(side = 'left')
# Packing the frames
self.top_frame.pack()
self.bottom_frame.pack()
# Enter the tkinter main loop
tkinter.mainloop()
def do_something(self):
# Text Sets update the widgets above
self.texta.set(Steven Marcus')
self.textb.set('274 Baily Drive')
self.textc.set('Waynesville, NC 27999')
my_gui = MyGUI()
Sent from [1]Mail for Windows 10
References
Visible links
1. https://go.microsoft.com/fwlink/?LinkId=550986
More information about the Tutor
mailing list