-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgui_tkinter.py
160 lines (143 loc) · 5.37 KB
/
gui_tkinter.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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
'''
Out of all the GUI methods, tkinter is the most commonly used method.
It is a standard Python interface to the Tk GUI toolkit shipped with Python.
To create a tkinter app:
1-Importing the module – tkinter
2-Create the main window (container)
3-Add any number of widgets to the main window
4-Apply the event Trigger on the widgets.
There are two main methods:
-Tk(screenName=None, baseName=None, className=’Tk’, useTk=1):
To create a main window
-mainloop(): is used when your application is ready to run.
mainloop() is an infinite loop used to run the application, wait for an event
to occur and process the event as long as the window is not closed.
'''
# import tkinter as tk
# # Button Click Event Function
# def action():
# btt.configure(text = "** I have been Clicked! ***", background = 'pink', foreground = 'blue')
# lbl.configure(foreground = 'red' , text= 'after click')
# lbl2.configure(foreground = 'blue' , text= 'Hi ' + txt_name.get())
# # btt.configure(state='disabled')
# txt_name.configure(state = 'disabled')
# win = tk.Tk()
# win.title('First form for teaching GUI')
# # setting the minimun size of the main window
# win.minsize(800,400)
# # This code helps to disable windows from resizing
# win.resizable(False, False)
# screen_width = win.winfo_screenwidth()
# screen_height = win.winfo_screenheight()
# print(screen_width, screen_height)
# # #addning a label
# lbl = tk.Label(win, text = 'Name')
# lbl.grid(column = 0 , row=0)
# from tkinter import ttk
# # # The ttk module has some advanced widgets that make our GUI look great.
# lbl2 = ttk.Label(win, text= 'Lastname')
# lbl2.grid(column=0, row=1)
# txt_name = tk.Entry(win , width = 20)
# txt_name.grid(row=0 , column=1)
# txt_name.focus() #Place cursor into entry name
# # ########################################
# # # start GUI
# # ########################################
# btt = tk.Button(win, text='Click Me!', width=25, command = action)
# btt.grid(row=2 , column=0)
# btt2 = tk.Button(win, text='Stop', width=20, command = win.destroy)
# btt2.grid(row = 2 , column = 1)
# btt3 = tk.Button(win, text='Nothing', width=25)
# btt3.grid(row=2 , column=2)
# win.mainloop()
#-----------------------create combobox-----------------------------------
# import tkinter as tk
# from tkinter import ttk
# def show_number():
# msg = 'Hi ' + txt_name.get() + ' your id is ' + number_choosen.get()
# lbl_name.configure(text = msg , foreground = 'red')
# win = tk.Tk()
# lbl_name = tk.Label(win, text = 'Choose a number:')
# lbl_name.grid(column=0, row=0)
# number_choosen = ttk.Combobox(win, width = 12 , state='readonly' )
# number_choosen['values'] = (1, 2, 4, 42, 100)
# number_choosen.grid(column=1, row =0)
# number_choosen.current(0)
# txt_name = tk.Entry(win , width = 12)
# txt_name.grid(row=0 , column=2)
# txt_name.focus() #Place cursor into entry name
# btt = tk.Button(win, text='Click Me!', width=25, command = show_number)
# btt.grid(row=0, column=3)
# win.mainloop()
# #----------------------------------------------------------
from tkinter import *
# root = Tk()
# frame = Frame(root)
# frame.pack()
# bottomframe = Frame(root)
# bottomframe.pack( side = BOTTOM )
# redbutton = Button(frame, text = 'Red', fg ='red')
# redbutton.pack( side = LEFT)
# greenbutton = Button(frame, text = 'Brown', fg='brown')
# greenbutton.pack( side = LEFT )
# bluebutton = Button(frame, text ='Blue', fg ='blue')
# bluebutton.pack( side = LEFT )
# blackbutton = Button(frame, text ='Black', fg ='black')
# blackbutton.pack( side = BOTTOM)
# root.mainloop()
# #----------------------------------------------------------
# top = Tk()
# Lb = Listbox(top)
# Lb.insert(1, 'Python')
# Lb.insert(2, 'Java')
# Lb.insert(3, 'C++')
# Lb.insert(4, 'Any other')
# # Lb.pack()
# Lb.grid(column=0, row=0)
# top.mainloop()
# #----------------------------------------------------------
# root = Tk()
# menu = Menu(root)
# root.config(menu=menu)
# filemenu = Menu(menu)
# menu.add_cascade(label='File', menu=filemenu)
# filemenu.add_command(label='New')
# filemenu.add_command(label='Open...')
# filemenu.add_separator()
# filemenu.add_command(label='Exit', command=root.quit)
# helpmenu = Menu(menu)
# menu.add_cascade(label='Help', menu=helpmenu)
# helpmenu.add_command(label='About')
# ourMessage ='This is our Message'
# messageVar = Message(root, text = ourMessage)
# messageVar.config(bg='lightgreen')
# messageVar.pack()
# root.mainloop()
# #----------------------------------------------------------
# root = Tk()
# v = IntVar()
# Radiobutton(root, text='GfG', variable=v, value=1).pack(anchor=W)
# Radiobutton(root, text='MIT', variable=v, value=2).pack(anchor=W)
# w = Scale(root, from_=0, to=42)
# w.pack()
# w = Scale(root, from_=0, to=200, orient=HORIZONTAL)
# w.pack()
# mainloop()
# #----------------------------------------------------------
# from tkinter import *
# root = Tk()
# scrollbar = Scrollbar(root)
# scrollbar.pack( side = RIGHT, fill = Y )
# mylist = Listbox(root, yscrollcommand = scrollbar.set )
# for line in range(10):
# mylist.insert(END, 'This is line number' + str(line))
# mylist.pack( side = LEFT, fill = BOTH )
# scrollbar.config( command = mylist.yview )
# mainloop()
# #----------------------------------------------------------
from tkinter import *
root = Tk()
root.title('Programing')
top = Toplevel()
top.title('Python')
top.mainloop()