class myApp(tk.Tk):
def __init__(self) -> None:
super().__init__()
self.title("Title of App")
self.geometry("450x400+450+150")
self.create_ui()
def create_ui(self) -> None:
# menu
menubar = tk.Menu(self)
self.config(menu=menubar)
# submenus cascading
file_menu = tk.Menu(menubar)
file_menu.add_command(label="test", command=partial(self.a_comm, text_content="File menu"))
conf_menu = tk.Menu(menubar)
conf_menu.add_command(label="test", command=partial(self.a_comm, text_content="Config menu"))
menubar.add_cascade(label='File', menu=file_menu)
menubar.add_cascade(label='Config', menu=conf_menu)
# frame
frame = ttk.Frame(self)
frame.pack(fill=tk.BOTH, expand=1)
# button
test_button = ttk.Button(frame, text="Test", command=partial(self.a_comm, text_content="Button"))
test_button.pack(anchor="e", padx=5, pady=5)
# text
self.text = tk.Text(frame)
self.text.pack(fill=tk.BOTH, expand=1)
if messagebox.askquestion("Title", "Yes or No?", icon="warning",) == "yes":
self.a_comm("YES!!")
else:
self.a_comm("NO MAN!! "*3)
def a_comm(self, text_content: str) -> None:
self.text.insert(tk.END, text_content+"\n")TkInter
A popular GUI package
Testing tkinter
A simple GUI that just enters lines of text related to the activated widget.
Then run the app
app = myApp()
app.mainloop()