-
Notifications
You must be signed in to change notification settings - Fork 0
/
xovich.py
98 lines (86 loc) · 3.66 KB
/
xovich.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
"""
The Xovich program enables the user to add "ovich" at the end of their name!
"""
from tkinter import *
from tkinter import messagebox#, font
class Main(Frame):
"""The GUI"""
def __init__(self, GUIman):
"""Initalises the GUI itself"""
super(Main, self).__init__(GUIman)
self.master.protocol("WM_DELETE_WINDOW",self.confirmclosure)
self.pack()
self.create()
def create(self):
"""Create the fields for the user to play with."""
Label(self, text="Enter a name and (optionally) a second name. Expect an -ovich at the end!\nYou can also add an \"Ilya\" at the middle!").pack()
Label(self).pack()
Label(self, text="First name").pack()
self.firstnamefield = Entry(self, width=35)
self.firstnamefield.insert(0,"Example")
self.firstnamefield.pack()
Label(self, text="Last name").pack()
self.lastnamefield = Entry(self, width=35, state=NORMAL)
self.lastnamefield.insert(0, "Named")
self.lastnamefield.pack()
Label(self).pack()
self.ilya = IntVar()
self.addilyabox = Checkbutton(self, text="Add \"Ilya\" in the middle", variable=self.ilya)
self.addilyabox.pack()
self.fal = IntVar()
self.setfirstaslast = Checkbutton(self, text="Set last name as first name", command=self.greyout, variable=self.fal)
self.setfirstaslast.pack()
Label(self).pack()
self.processbutton = Button(self, text="Confirm selection", command=self.showmakeovich)
self.processbutton.pack()
def greyout(self):
"""Greys out the "last name" field if the user wants it to be the same as their first name"""
#print(self.fal.get())
if self.fal.get() == 1:
self.lastnamefield.config(state=DISABLED)
else:
self.lastnamefield.config(state=NORMAL)
def confirmclosure(self):
"""Asks the user if they really want to close the program (before actually closing it)"""
if messagebox.askyesno("End","Are you sure you want to exit?!", icon="warning"):
self.master.destroy()
def showmakeovich(self):
"""Does the actual processing!"""
messagebox.showinfo("New name", f"Your new name is {self.makeovich()}!")
def makeovich(self):
"""The function for actually making the new name"""
firstname = self.firstnamefield.get()
if self.lastnamefield.cget('state') == DISABLED:
lastname = firstname
else:
lastname = self.lastnamefield.get()
if self.ilya.get() == 1 and len(firstname) != 0:
newname = firstname + " Ilya " + lastname
elif len(firstname) != 0 and len(lastname) != 0:
newname = firstname + " " + lastname
elif len(firstname) == 0 and len(lastname) == 0 and self.ilya.get() == 1:
newname = "Ilya I Don't Got No Name"
elif len(firstname) == 0 and self.ilya.get() == 1:
newname = "Ilya " + lastname
elif len(firstname) + len(lastname) == 0:
newname = "I Don't Got No Name"
elif len(firstname) == 0:
newname = lastname
elif len(lastname) == 0:
newname = firstname
else:
newname = "I Don't Got No Name"
newname += "ovich"
#print(newname)
return newname
"""TODO: Fix the if-statements to make sure they return results that I like. Also, make more unit tests."""
def createGUI():
"""Creates the, well, GUI!"""
root = Tk()
root.title("Xovich")
root.geometry("500x325")
xovich = Main(root)
return xovich
if __name__ == "__main__":
"""What to run when executed"""
createGUI().mainloop()