-
Notifications
You must be signed in to change notification settings - Fork 0
/
MainApp.py
67 lines (50 loc) · 2.14 KB
/
MainApp.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
64
65
66
67
from tkinter import Tk, Label, Button, Entry, ttk
from tkcalendar import Calendar, DateEntry
import tkinter as tk
from tkinter import ttk
class MyFirstGUI:
def __init__(self, master):
self.master = master
master.title("A simple GUI")
self.someThing = "abbaa"
self.label = Label(master, text="This is our first GUI!")
self.label.pack()
self.editText = Entry(master)
self.editText.insert(0, 'default text')
self.editText.pack()
# state= readonly prevents typing in combo box.
# https://stackoverflow.com/a/44959378/680268
self.comboExample = ttk.Combobox(state="readonly",
values=[
"January",
"February",
"March",
"April"])
self.comboExample.pack()
# default the selection
self.comboExample.current(1)
self.greet_button = Button(master, text="Set Date", command=self.show_calendar_selector)
self.greet_button.pack()
self.greet_button = Button(master, text="Save", command=self.handle_save)
self.greet_button.pack()
def show_calendar_selector(self):
win = tk.Toplevel()
win.wm_title("Window")
self.datePicker = Calendar(win, font="Arial 14", selectmode='day', locale='en_US',
cursor="hand1", year=2018, month=2, day=5)
self.datePicker.pack(fill="both", expand=False)
setDateButton = ttk.Button(win, text="Okay", command=win.destroy)
setDateButton.pack()
def handle_save(self):
print("Greetings!")
print(self.someThing)
print("edit field contains: ", self.editText.get())
print("combo box selected item: ", self.comboExample.get())
print("combo box selected index: ", self.comboExample.current())
if hasattr(self, 'datePicker'):
print("selected date: ", self.datePicker.get_date())
else:
print("why you no set Date?!")
root = Tk()
my_gui = MyFirstGUI(root)
root.mainloop()