forked from joancatala/TKinter-GUI
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtkinter.py
More file actions
348 lines (286 loc) · 11.4 KB
/
Copy pathtkinter.py
File metadata and controls
348 lines (286 loc) · 11.4 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
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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
import sys
import Tkinter as root
class Dashboard():
def __init__(self,title,length,breadth):
self.window = root.Tk()
self.window.title(title)
# get screen width and height
ws = self.window.winfo_screenwidth()
hs = self.window.winfo_screenheight()
# calculate position x, y
x = (ws/2) - (length/2)
y = (hs/2) - (breadth/2)
self.window.geometry('%dx%d+%d+%d' % (length, breadth, x, y))
# To show the main window with widget like checkbox, buttons etc.
def Display(self, choice = True):
self.window.mainloop()
return
#Adding Button,Checkbox,textarea,radiobutton etc. as a widget which depends on passing argument
def Add(self,widget):
name = widget.name
if(name == "button"):
fram = self.fram(widget) #Setting the widget into a fram
widget.controller = root.Button(fram, text=widget.title, command=widget.call)
widget.controller.pack(fill=root.BOTH, expand=1)
elif(name == "textarea"):
fram = self.fram(widget) #Setting the widget into a fram
widget.controller = root.Text(fram)
widget.controller.pack(fill=root.BOTH, expand=1)
elif(name == "checkbox"):
fram = self.fram(widget) # Setting the widget into a fram
var = widget.value # Widget.value contain whether the widget need to be marked
widget.value = root.IntVar()
if(var):
widget.value.set(1)
else:
widget.value.set(0)
widget.controller = root.Checkbutton(fram, text=widget.title, variable=widget.value, onvalue=1, offvalue=0) # Creating the widget checkbutton
widget.controller.grid(sticky=root.W)
elif(name == "radiobox"):
fram = self.fram1(widget.width,widget.height,widget.positions_X[0],widget.positions_Y[0])
widget.controller = [] #creating the list for widgets
radio_var = widget.value # Widget.value contain whether the widget need to be marked
widget.value = root.IntVar()
radio_controller = root.Radiobutton(fram, text=widget.labels[0], variable=widget.value, value=0)
radio_controller.pack(fill=root.BOTH, expand=1)
widget.controller.append(radio_controller)
for i in range(1,len(widget.labels)): #for each radiobutton , creating radiobutton acc, to pos.
fram = self.fram1(widget.width,widget.height,widget.positions_X[i],widget.positions_Y[i])
radio_controller = root.Radiobutton(fram, text=widget.labels[i], variable=widget.value,value=i)
radio_controller.pack(fill=root.BOTH, expand=1) #packing the radiobuttons
widget.controller.append(radio_controller)
elif(name=="textbox"):
fram = self.fram(widget)
widget.controller = root.Entry(fram)
widget.controller.pack()
elif(name=="Password"):
fram = self.fram(widget)
widget.controller = root.Entry(fram,show="*")
widget.controller.pack()
elif(name=="ValueList"):
array = ['']
array[0] = widget.value
array = array + widget.choices
widget.list_var = root.StringVar()
widget.list_var.set(array[0])
fram = self.fram(widget)
widget.controller = apply(root.OptionMenu, (fram, widget.list_var) + tuple(array))
widget.controller.pack(fill=root.BOTH, expand=1)
elif(name=="spin"):
fram = self.fram(widget)
widget.controller=root.Spinbox(fram,from_=widget.min,to=widget.max)
widget.controller.pack()
elif(name == "LabelText"):
temp = widget.label_var
widget.label_var = root.StringVar()
widget.label_var.set(temp)
fram = self.fram(widget)
widget.controller = root.Label(fram, textvariable=widget.label_var)
widget.controller.pack(fill=root.BOTH, expand=1)
def fram(self,widget): # Creating frame for widgets , thus setting width and height of widget
fram = root.Frame(self.window, width=widget.width,height=widget.height)
fram.pack_propagate(0)
fram.pack()
fram.place(x=widget.position_X,y=widget.position_Y) #positoin of widget within fram
return fram
def fram1(self,W,H,X,Y): #Creating frame for radiobuttons
fram = root.Frame(self.window, width=W,height=H)
fram.pack_propagate(0)
fram.pack()
fram.place(x=X,y=Y)
return fram
# For Button Widget ........................
class Create_button:
controller = None
call = None
Type = None
def __init__(self,posX,posY,title="MyButton",length=100,breadth=30): #constructor setting pos_x,pos_y, width and height
self.name = "button"
self.title = title
self.position_X = posX
self.position_Y = posY
self.width = length
self.height = breadth
def Click_listener(self,method): #method for handling click Events
if(self.controller == None):
self.call = method
else:
self.controller.callback(method)
return True
# For TextArea Widget ........................
class Text_area:
controller = None
def __init__(self,posX,posY,length=300,breadth=200,text=""): #constructor setting pos_x,pos_y , width and height
self.name = "textarea"
self.position_X = posX
self.position_Y = posY
self.width = length
self.height = breadth
def Set_text(self,text): #Setting text for textarea
if(self.controller == None):
self.text = text
else:
self.controller.delete(1.0, root.END)
self.controller.insert(root.INSERT,text)
return True
def Get_text(self): # Initializing the TextArea
if(self.controller == None):
return self.text
else:
return self.controller.get(1.0, root.END)
def Append_text(self,text): # For Appending the exisitng text in TextArea
print "narender"
if(self.controller == None):
self.text = self.text + text
else:
self.controller.insert(root.INSERT, text)
return True
def Clear_area(self): # For Clearing the TextArea
self.controller.delete(1.0, root.END)
return True
#For TextBox Widget .........................
class Text_field:
def __init__(self,posX,posY,text="",length=250,breadth=25):
self.name="textbox"
self.position_X = posX
self.position_Y = posY
self.width = length
self.height = breadth
def Set_text(self,text): # Setting text for textarea
if(self.controller == None):
self.text = text
else:
self.controller.delete(1.0, root.END)
self.controller.insert(root.INSERT,text)
return True
def Get_text(self): # Returning text which textarea is holding
if(self.controller == None):
return self.text
else:
return self.controller.get()
def Clear_field(self): # Clearing the textField
self.controller.delete(0,root.END)
return True
#For TextBox Widget .........................
class Password_field:
def __init__(self,posX,posY,text="",length=250,breadth=25):
self.name="Password"
self.position_X = posX
self.position_Y = posY
self.width = length
self.height = breadth
def Set_text(self,text): #Setting text in password form for textarea
if(self.controller == None):
self.text = text
else:
self.controller.delete(1.0, root.END)
self.controller.insert(root.INSERT,text)
return True
def Get_text(self): # Returning text which textarea is holding
if(self.controller == None):
return self.text
else:
return self.controller.get()
def Clear_field(self): # Clearing the textField
self.controller.delete(0,root.END)
return True
# For Label Text
class Static_text:
controller = None
label_var = ""
def __init__(self,posX,posY,length=150,breadth=30,text=""):
self.label_var=text
self.name= "LabelText"
self.position_X = posX
self.position_Y = posY
self.width = length
self.height = breadth
def Set_value(self,text): # Value to be set for Label
if(self.controller == None):
self.text = text
else:
self.label_var.set(text)
return True
# For CheckBox Widget ........................
class Check_box:
controller = None
value = True
def __init__(self,posX,posY,title,length,breadth): #constructor setting pos_x,pos_y , width and height
self.name = "checkbox"
self.title=title
self.position_X = posX
self.position_Y = posY
self.width = length
self.height = breadth
def Set_checked(self,value=True): #setting marked or unmarked for checkbox
if(self.controller == None):
self.value = value
else:
if(value):
self.controller.select()
else:
self.controller.deselect()
def Is_checked(self): #Returning the value of checkbox(is it marked or unmarked)
if(self.controller == None):
return self.value
else:
if(self.value.get() == 1):
return True
else:
return False
# For RadioButton Widget ........................
class Radio_button:
controller = None
selected_index = None
Type = None
value = 0
def __init__(self,label1,posX,posY):#Returning the value of checkbox(is it marked or unmarked)
self.positions_X = [] #creating empty list for positions for radiobuttons
self.positions_Y = []
self.labels = []
self.name = "radiobox"
self.width=100
self.height=50
self.Add_radio_button(label1,posX,posY)
def Add_radio_button(self,label,posX,posY): #Adding the label and position for a particular radiobutton
self.labels.append(label)
self.positions_X.append(posX) #Appending the position in the position LIST
self.positions_Y.append(posY)
return True
def Get_selected(self): #Returning the value for radiobutton(marked or unmarked)
for i in range(len(self.controller)):
if(self.value.get()==i):
return self.labels[i]
return None
# For Drop Down List
class Drop_list:
controller = None
Type = None
list_var = 0
name=None
def __init__(self,posX,posY,name1,values,length=100,breadth=27):
self.name = "ValueList"
self.choices = values
self.position_X = posX
self.position_Y = posY
self.width = length
self.height = breadth
self.value = name1
def Get_value(self): # Getting the value from the drop down List
if(self.controller == None):
return self.title
else:
return self.list_var.get()
#For Spin List
class Spin_list:
def __init__(self,posX,posY,length=100,breadth=25,minimum=0,maximum=100):
self.name="spin"
self.position_X = posX
self.position_Y = posY
self.width=length
self.height=breadth
self.min = minimum
self.max = maximum
def Get_value(self):
return 6
########################################################################################################