/
example5.py
63 lines (46 loc) · 1.75 KB
/
example5.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
"""Pygubu and Tkinter: menu in main window, callback functions, tearoff menu (working example)."""
#
# (C) Copyright 2020 Pavel Tisnovsky
#
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Eclipse Public License v1.0
# which accompanies this distribution, and is available at
# http://www.eclipse.org/legal/epl-v10.html
#
# Contributors:
# Pavel Tisnovsky
#
# Example5.py
import tkinter as tk
import pygubu
class Example5App(pygubu.TkApplication):
"""Class representing a Tkinter based application."""
def _create_ui(self):
"""Construct and initializes all UI-related data structures."""
# step #1: Create a builder
self.builder = builder = pygubu.Builder()
# step #2: Load an ui file
builder.add_from_file("example5.ui")
# step #2B: Specify path to images and other resources
builder.add_resource_path(".")
# step #3: Create the mainwindow
self.mainwindow = builder.get_object("MainWindow", self.master)
# step #4: Set main menu
self.mainmenu = menu = builder.get_object("MainMenu", self.master)
self.set_menu(menu)
# step #5: Configure callbacks
builder.connect_callbacks(self)
def on_button_clicked(self):
"""Define handler for Quit button."""
tk.messagebox.showinfo("Message", "You clicked on Quit button")
root.destroy()
def on_command_quit_selected(self):
"""Define handler for Quit command."""
tk.messagebox.showinfo("Message", "You selected Quit command")
root.destroy()
if __name__ == "__main__":
# needed to have a menu
root = tk.Tk()
# run the application
app = Example5App(root)
app.run()