def __init__(self): self.window = self.build_window() self.panel = Indicator(self.window, font=("Arial", 12), width=30, height=3) self.panel.pack() self.panel.place(x=200, y=0, anchor="n") self.menu = tk.Menu(self.window) self.filemenu = tk.Menu(self.menu) self.menu.add_cascade(label="file", menu=self.filemenu) self.editmenu = tk.Menu(self.menu) self.menu.add_cascade(label="edit", menu=self.editmenu) self.submenu = tk.Menu(self.filemenu) self.filemenu.add_cascade(label="import", menu=self.submenu) self.filemenu.add_command(label="New", command=self.do_job()) self.filemenu.add_command(label="Open", command=self.do_job()) self.filemenu.add_command(label="Save", command=self.do_job()) self.filemenu.add_command(label="exit", command=self.quit) self.editmenu.add_command(label="cut", command=self.do_job()) self.editmenu.add_command(label="copy", command=self.do_job()) self.editmenu.add_command(label="paste", command=self.do_job()) self.window.config(menu=self.menu) self.quit_button = Button(self.window, text="Quit", width=10, height=1) self.quit_button.set("command", self.quit) self.quit_button.pack() self.quit_button.place(x=200, y=260, anchor="s")
def __init__(self): self.window = self.build_window() self.panel = Indicator(self.window, font=("Arial", 12), width=30, height=3) self.panel.pack() self.panel.place(x=200, y=0, anchor="n") self.var1 = tk.BooleanVar(value=False) self.check_button_01 = tk.Checkbutton(self.window, text='python', variable=self.var1, onvalue=True, offvalue=False, command=self.update_text) self.check_button_01.pack() self.check_button_01.place(x=200, y=100, anchor="n") self.var2 = tk.BooleanVar(value=False) self.check_button_02 = tk.Checkbutton(self.window, text='C++', variable=self.var2, onvalue=True, offvalue=False, command=self.update_text) self.check_button_02.pack() self.check_button_02.place(x=200, y=150, anchor="n") self.quit_button = Button(self.window, text="Quit", width=10, height=2) self.quit_button.set("command", self.quit) self.quit_button.pack() self.quit_button.place(x=200, y=280, anchor="s")
def __init__(self): self.window = self.build_window() self.panel = Indicator(self.window, font=("Arial", 12), width=30, height=3) self.panel.pack() self.panel.place(x=200, y=0, anchor="n") self.var0 = tk.StringVar(value="") self.radio_button_01 = tk.Radiobutton(self.window, text='Option A', variable=self.var0, value='A', command=self.update_text) self.radio_button_01.pack() self.radio_button_01.place(x=200, y=100, anchor="n") self.radio_button_02 = tk.Radiobutton(self.window, text='Option B', variable=self.var0, value='B', command=self.update_text) self.radio_button_02.pack() self.radio_button_02.place(x=200, y=150, anchor="n") self.var1 = tk.StringVar(value="") self.radio_button_03 = tk.Radiobutton(self.window, text='Option C', variable=self.var1, value='C', command=self.update_text) self.radio_button_03.pack() self.radio_button_03.place(x=200, y=200, anchor="n") self.var2 = tk.StringVar(value="") self.radio_button_04 = tk.Radiobutton(self.window, text='Option D', variable=self.var2, value='D', command=self.update_text) self.radio_button_04.pack() self.radio_button_04.place(x=200, y=250, anchor="n") self.panel.set_text( f"var0: {self.var0.get()}, var1: {self.var1.get()}, var2: {self.var2.get()}" ) self.quit_button = Button(self.window, text="Quit", width=10, height=2) self.quit_button.set("command", self.quit) self.quit_button.pack() self.quit_button.place(x=200, y=380, anchor="s")
def __init__(self): self.window = self.build_window() self.panel = Indicator(self.window, bg="red", font=("Arial", 12), width=30, height=3) self.panel.pack() self.panel.place(x=200, y=80, anchor="n") self.button = Button(self.window, text="Ok", width=10, height=2) self.button.set("command", self.click_button()) self.button.pack() self.button.place(x=20, y=280, anchor="sw") self.quit_button = Button(self.window, text="Quit", width=10, height=2) self.quit_button.set("command", self.quit) self.quit_button.pack() self.quit_button.place(x=380, y=280, anchor="se")
class UserInterface: def __init__(self): self.window = self.build_window() self.panel = Indicator(self.window, font=("Arial", 12), width=30, height=3) self.panel.pack() self.panel.place(x=200, y=0, anchor="n") self.var1 = tk.BooleanVar(value=False) self.check_button_01 = tk.Checkbutton(self.window, text='python', variable=self.var1, onvalue=True, offvalue=False, command=self.update_text) self.check_button_01.pack() self.check_button_01.place(x=200, y=100, anchor="n") self.var2 = tk.BooleanVar(value=False) self.check_button_02 = tk.Checkbutton(self.window, text='C++', variable=self.var2, onvalue=True, offvalue=False, command=self.update_text) self.check_button_02.pack() self.check_button_02.place(x=200, y=150, anchor="n") self.quit_button = Button(self.window, text="Quit", width=10, height=2) self.quit_button.set("command", self.quit) self.quit_button.pack() self.quit_button.place(x=200, y=280, anchor="s") def build_window(self): window = tk.Tk() window.title("user interface") window.geometry("400x300") return window def update_text(self): if self.var1.get() and self.var2.get(): text = "both" elif self.var1.get(): text = "python" elif self.var2.get(): text = "C++" else: text = "Neither" self.panel.set_text(text) return def quit(self): self.window.quit() return def run(self): self.window.mainloop()
def __init__(self): self.window = self.build_window() self.panel = Indicator(self.window, font=("Arial", 12), width=30, height=3) self.panel.pack() self.panel.place(x=200, y=0, anchor="n") self.listbox = Listbox(self.window, ["A", "B", "C", "D"], height=4) self.listbox.pack() self.listbox.place(x=200, y=80, anchor="n") self.button = Button(self.window, text="Ok", width=10, height=1) self.button.set("command", self.click_button) self.button.pack() self.button.place(x=200, y=220, anchor="s") self.quit_button = Button(self.window, text="Quit", width=10, height=1) self.quit_button.set("command", self.quit) self.quit_button.pack() self.quit_button.place(x=200, y=260, anchor="s")
class UserInterface: def __init__(self): self.window = self.build_window() self.panel = Indicator(self.window, font=("Arial", 12), width=30, height=3) self.panel.pack() self.panel.place(x=200, y=0, anchor="n") self.menu = tk.Menu(self.window) self.filemenu = tk.Menu(self.menu) self.menu.add_cascade(label="file", menu=self.filemenu) self.editmenu = tk.Menu(self.menu) self.menu.add_cascade(label="edit", menu=self.editmenu) self.submenu = tk.Menu(self.filemenu) self.filemenu.add_cascade(label="import", menu=self.submenu) self.filemenu.add_command(label="New", command=self.do_job()) self.filemenu.add_command(label="Open", command=self.do_job()) self.filemenu.add_command(label="Save", command=self.do_job()) self.filemenu.add_command(label="exit", command=self.quit) self.editmenu.add_command(label="cut", command=self.do_job()) self.editmenu.add_command(label="copy", command=self.do_job()) self.editmenu.add_command(label="paste", command=self.do_job()) self.window.config(menu=self.menu) self.quit_button = Button(self.window, text="Quit", width=10, height=1) self.quit_button.set("command", self.quit) self.quit_button.pack() self.quit_button.place(x=200, y=260, anchor="s") def build_window(self): window = tk.Tk() window.title("user interface") window.geometry("400x300") return window def do_job(self): cnt = 0 def fn(): nonlocal cnt cnt += 1 self.panel.set_text(f"op num: {cnt}") return return fn def quit(self): self.window.quit() return def run(self): self.window.mainloop()
class UserInterface: def __init__(self): self.window = self.build_window() self.panel = Indicator(self.window, font=("Arial", 12), width=30, height=3) self.panel.pack() self.panel.place(x=200, y=0, anchor="n") self.listbox = Listbox(self.window, ["A", "B", "C", "D"], height=4) self.listbox.pack() self.listbox.place(x=200, y=80, anchor="n") self.button = Button(self.window, text="Ok", width=10, height=1) self.button.set("command", self.click_button) self.button.pack() self.button.place(x=200, y=220, anchor="s") self.quit_button = Button(self.window, text="Quit", width=10, height=1) self.quit_button.set("command", self.quit) self.quit_button.pack() self.quit_button.place(x=200, y=260, anchor="s") def build_window(self): window = tk.Tk() window.title("user interface") window.geometry("400x300") return window def click_button(self): idx = self.listbox.component.curselection() selection = self.listbox.component.get(idx) if idx else "null" self.panel.set_text(f"your choice is {selection}") return def quit(self): self.window.quit() return def run(self): self.window.mainloop()
class UserInterface: def __init__(self): self.window = self.build_window() self.panel = Indicator(self.window, font=("Arial", 12), width=30, height=3) self.panel.pack() self.panel.place(x=200, y=80, anchor="n") self.entry = Entry(self.window, show="*") self.entry.pack() self.entry.place(x=200, y=160, anchor="n") self.button = Button(self.window, text="Ok", width=10, height=2) self.button.set("command", self.click_button) self.button.pack() self.button.place(x=20, y=280, anchor="sw") self.quit_button = Button(self.window, text="Quit", width=10, height=2) self.quit_button.set("command", self.quit) self.quit_button.pack() self.quit_button.place(x=380, y=280, anchor="se") def build_window(self): window = tk.Tk() window.title("user interface") window.geometry("400x300") return window def click_button(self): self.panel.set_text(self.entry.get()) pass def quit(self): self.window.quit() return def run(self): self.window.mainloop()
class UserInterface: def __init__(self): self.window = self.build_window() self.panel = Indicator(self.window, bg="red", font=("Arial", 12), width=30, height=3) self.panel.pack() self.panel.place(x=200, y=80, anchor="n") self.button = Button(self.window, text="Ok", width=10, height=2) self.button.set("command", self.click_button()) self.button.pack() self.button.place(x=20, y=280, anchor="sw") self.quit_button = Button(self.window, text="Quit", width=10, height=2) self.quit_button.set("command", self.quit) self.quit_button.pack() self.quit_button.place(x=380, y=280, anchor="se") def build_window(self): window = tk.Tk() window.title("user interface") window.geometry("400x300") return window def click_button(self): status = False def fn(): nonlocal status if not status: self.panel.set_text("hello world!") self.panel.set("bg", "green") else: self.panel.set_text("") self.panel.set("bg", "red") status = not status return return fn def quit(self): self.window.quit() return def run(self): self.window.mainloop()
class UserInterface: def __init__(self): self.window = self.build_window() self.panel = Indicator(self.window, font=("Arial", 12), width=30, height=3) self.panel.pack() self.panel.place(x=200, y=0, anchor="n") self.var0 = tk.StringVar(value="") self.radio_button_01 = tk.Radiobutton(self.window, text='Option A', variable=self.var0, value='A', command=self.update_text) self.radio_button_01.pack() self.radio_button_01.place(x=200, y=100, anchor="n") self.radio_button_02 = tk.Radiobutton(self.window, text='Option B', variable=self.var0, value='B', command=self.update_text) self.radio_button_02.pack() self.radio_button_02.place(x=200, y=150, anchor="n") self.var1 = tk.StringVar(value="") self.radio_button_03 = tk.Radiobutton(self.window, text='Option C', variable=self.var1, value='C', command=self.update_text) self.radio_button_03.pack() self.radio_button_03.place(x=200, y=200, anchor="n") self.var2 = tk.StringVar(value="") self.radio_button_04 = tk.Radiobutton(self.window, text='Option D', variable=self.var2, value='D', command=self.update_text) self.radio_button_04.pack() self.radio_button_04.place(x=200, y=250, anchor="n") self.panel.set_text( f"var0: {self.var0.get()}, var1: {self.var1.get()}, var2: {self.var2.get()}" ) self.quit_button = Button(self.window, text="Quit", width=10, height=2) self.quit_button.set("command", self.quit) self.quit_button.pack() self.quit_button.place(x=200, y=380, anchor="s") def build_window(self): window = tk.Tk() window.title("user interface") window.geometry("400x400") return window def update_text(self): self.panel.set_text( f"var0: {self.var0.get()}, var1: {self.var1.get()}, var2: {self.var2.get()}" ) return def quit(self): self.window.quit() return def run(self): self.window.mainloop()