-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtkinterModule.py
More file actions
69 lines (46 loc) · 2.01 KB
/
Copy pathtkinterModule.py
File metadata and controls
69 lines (46 loc) · 2.01 KB
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
from tkinter import *
from PIL import Image, ImageTk
class Window(Frame): # It is the base frame and in programming we call the gui output as a frame and not as a window.
def client_exit(self):
exit()
def client_undo(self):
pass
def showImg(self):
load = Image.open('pic.png')
render = ImageTk.PhotoImage(load)
img = Label(self, image = render)
img.img = render
img.place(x = 0, y = 0)
pass
def showTxt(self):
text = Label(self, text = 'Hey there good looking!')
text.pack()
pass
def __init__(self, master = None): # You can replace self with anything you want.
Frame.__init__(self, master)
self.master = master # This makes it our master(main) frame.
self.init_window()
input('Input to exit!')
def init_window(self): # You can name this function anything, it is made by us.
varString = StringVar()
myInput = Entry(root, textvariable=varString).pack()
varInput = varString.get()
print(varInput) # This doe'nt work.
self.master.title("GUI")
self.pack(fill = BOTH, expand = 1)
quitButton = Button(self, text = "Quit!", command = self.client_exit) # You can write client_exit as anything you want, the button just starts a new function.
quitButton.place(x = 349, y = 259)
menu = Menu(self.master) # menu can be varMenu
self.master.config(menu = menu)
file = Menu(menu)
file.add_command(label = 'Exit', command = self.client_exit)
menu.add_cascade(label = 'File', menu = file)
edit = Menu(menu)
edit.add_command(label = 'Undo', command = self.client_undo)
edit.add_command(label = 'Show Image', command = self.showImg) # To show image directly use command = self.showImg()
edit.add_command(label = 'Show Text', command = self.showTxt)
menu.add_cascade(label = 'Edit', menu = edit)
root = Tk()
root.geometry("400x300")
app = Window(root)
root.mainloop()