|
1 |
| -import tkinter as tk |
2 |
| -from tkinter import ttk |
| 1 | +""" |
| 2 | +Author: RedFantom |
| 3 | +License: GNU GPLv3 |
| 4 | +Copyright (c) 2018 RedFantom |
| 5 | +""" |
| 6 | +import os |
| 7 | +import sys |
| 8 | +if sys.version_info.major == 3: |
| 9 | + import tkinter as tk |
| 10 | + from tkinter import ttk |
| 11 | +else: |
| 12 | + import Tkinter as tk |
| 13 | + import ttk |
3 | 14 |
|
4 |
| -window = tk.Tk() |
5 |
| -style = ttk.Style(window) |
6 |
| -window.eval("set dir /usr/lib/tcltk/gtkTtk0.5; source /usr/lib/tcltk/gtkTtk0.5/pkgIndex.tcl") |
7 |
| -window.tk.call("package", "require", "ttk::theme::gtkTtk"); |
8 |
| -print(style.theme_names()) |
9 | 15 |
|
10 |
| -style.theme_use("gtkTtk") |
11 |
| -ttk.Button(window, text="Destroy", command=window.destroy).pack() |
| 16 | +class Example(tk.Tk): |
| 17 | + """ |
| 18 | + Example that is used to create screenshots for new themes. |
| 19 | + """ |
| 20 | + def __init__(self): |
| 21 | + tk.Tk.__init__(self) |
| 22 | + # Create widgets |
| 23 | + self.menu = tk.Menu(self, tearoff=False) |
| 24 | + self.sub_menu = tk.Menu(self.menu, tearoff=False) |
| 25 | + self.sub_menu.add_command(label="Exit", command=self.destroy) |
| 26 | + self.menu.add_cascade(menu=self.sub_menu, label="General") |
| 27 | + self.config(menu=self.menu) |
| 28 | + self.label = ttk.Label(self, text="This is an example label.") |
| 29 | + self.dropdown = ttk.OptionMenu(self, tk.StringVar(), "First value", "Second Value") |
| 30 | + self.entry = ttk.Entry(self, textvariable=tk.StringVar(value="Default entry value.")) |
| 31 | + self.button = ttk.Button(self, text="Button") |
| 32 | + self.radio_one = ttk.Radiobutton(self, text="Radio one", value=True) |
| 33 | + self.radio_two = ttk.Radiobutton(self, text="Radio two", value=False) |
| 34 | + self.scroll = ttk.Scrollbar(self, orient=tk.VERTICAL) |
| 35 | + self.checked = ttk.Checkbutton(self, text="Checked", variable=tk.BooleanVar(value=True)) |
| 36 | + self.unchecked = ttk.Checkbutton(self, text="Unchecked") |
| 37 | + self.tree = ttk.Treeview(self, height=4, show=("tree", "headings")) |
| 38 | + self.setup_tree() |
| 39 | + self.progress = ttk.Progressbar(self, maximum=100, value=50) |
| 40 | + # Grid widgets |
| 41 | + self.grid_widgets() |
12 | 42 |
|
13 |
| -window.mainloop() |
| 43 | + def setup_tree(self): |
| 44 | + """Setup an example Treeview""" |
| 45 | + self.tree.insert("", tk.END, text="Example 1", iid="1") |
| 46 | + self.tree.insert("", tk.END, text="Example 2", iid="2") |
| 47 | + self.tree.insert("2", tk.END, text="Example Child") |
| 48 | + self.tree.heading("#0", text="Example heading") |
| 49 | + |
| 50 | + def grid_widgets(self): |
| 51 | + """Put widgets in the grid""" |
| 52 | + sticky = {"sticky": "nswe"} |
| 53 | + self.label.grid(row=1, column=1, columnspan=2, **sticky) |
| 54 | + self.dropdown.grid(row=2, column=1, **sticky) |
| 55 | + self.entry.grid(row=2, column=2, **sticky) |
| 56 | + self.button.grid(row=3, column=1, columnspan=2, **sticky) |
| 57 | + self.radio_one.grid(row=4, column=1, **sticky) |
| 58 | + self.radio_two.grid(row=4, column=2, **sticky) |
| 59 | + self.checked.grid(row=5, column=1, **sticky) |
| 60 | + self.unchecked.grid(row=5, column=2, **sticky) |
| 61 | + self.scroll.grid(row=1, column=3, rowspan=8, padx=5, **sticky) |
| 62 | + self.tree.grid(row=6, column=1, columnspan=2, **sticky) |
| 63 | + self.progress.grid(row=9, column=1, columnspan=2, padx=5, pady=5, **sticky) |
| 64 | + |
| 65 | + |
| 66 | +if __name__ == '__main__': |
| 67 | + window = Example() |
| 68 | + style = ttk.Style(window) |
| 69 | + window.eval("set dir /usr/lib/tcltk/tcl8.6/gtkTtk0.5; source /usr/lib/tcltk/tcl8.6/gtkTtk0.5/pkgIndex.tcl") |
| 70 | + window.tk.call("package", "require", "ttk::theme::gtkTtk") |
| 71 | + print(style.theme_names()) |
| 72 | + |
| 73 | + style.theme_use("gtkTtk") |
| 74 | + |
| 75 | + window.mainloop() |
14 | 76 |
|
0 commit comments