-
Notifications
You must be signed in to change notification settings - Fork 1
/
vat21.txt
415 lines (340 loc) · 9.44 KB
/
vat21.txt
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
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
import tkinter
top=tkinter.Tk()
top.mainloop()
top.title('counting seconds')
button=tkinter.Button(top,txt='stop',width=25,
command=top.destroy)
button.pack()
top.mainloop()
###
from tkinter import *
master= Tk()
Label(master,text='first name').grid(row=0)
Label(master,text='last name').grid(row=1)
e1=Entry(master)
e2=Entry(master)
e1.grid(row=0,column=1)
e2.grid(row=1,column=1)
mainloop()
### Drawing in GUI
import tkinter
top = tkinter.Tk()
canv = tkinter.Canvas(top,bg='blue',height=250,width=300)
coord= 10,50,240,210
arc=canv.create_arc(coord,start=0,extent=150,fill='red')
canv.pack()
top.mainloop()
#checkbox
from tkinter import *
import tkinter
top=tkinter.Tk()
CheckVar1=IntVar()
C1=Checkbutton(top,text='Music',variable=CheckVar1,onvalue=1,offvalue=0,height=5,width=20)
CheckVar2=IntVar()
C2=Checkbutton(top,text='Video',variable=CheckVar2,onvalue=1,offvalue=0,height=5,width=20)
C1.pack()
C2.pack()
top.mainloop()
#Textbox
from tkinter import *
import tkinter
top=tkinter.Tk()
L1=Label(top,text='User Name')
L1.pack(side=LEFT)
E1=Entry(top,bd=5)
E1.pack(side=RIGHT)
top.mainloop()
#Listbox
from tkinter import *
import tkinter
top=tkinter.Tk()
Lb1=Listbox(top)
Lb1.insert(1,'Python')
Lb1.insert(2,'Perl')
Lb1.insert(3,'C')
Lb1.insert(4,'PHP')
Lb1.insert(5,'JSP')
Lb1.insert(6,'Ruby')
Lb1.pack()
top.mainloop()
#Radiobutton/Option button
from tkinter import *
def sel():
selection='You selected the option'+str(var.get())
label.config(text=selection)
root=Tk()
var=IntVar()
R1=Radiobutton(root,text='Option 1',variable=var,value=1,command=sel)
R1.pack(anchor=W)
R2=Radiobutton(root,text='Option 2',variable=var,value=2,command=sel)
R2.pack(anchor=W)
R3=Radiobutton(root,text='Option 3',variable=var,value=3,command=sel)
R3.pack(anchor=W)
label=Label(root)
label.pack()
root.mainloop()
#scroll Bar
from tkinter import *
root=Tk()
scrollbar=Scrollbar(root)
scrollbar.pack(side=RIGHT,fill=Y)
mylist = Listbox(root,yscrollcommand=scrollbar.set)
for line in range(100):
mylist.insert(END,'this is line number'+str(line))
mylist.pack(side=LEFT,fill=BOTH)
scrollbar.config(command=mylist.yview)
root.mainloop()
#Button Function
from tkinter import *
root=Tk()
frame=Frame(root)
frame.pack()
bottomframe=Frame(root)
bottomframe.pack(side=BOTTOM)
red=Button(frame,text='Red',fg='red')
red.pack(side=LEFT)
green=Button(frame,text='Green',fg='red')
green.pack(side=LEFT)
blue=Button(frame,text='Blue',fg='blue')
blue.pack(side=LEFT)
black=Button(frame,text='Black',fg='black')
black.pack(side=BOTTOM)
root.mainloop()
#Menu
from tkinter import *
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')
mainloop()
#write a program to show a canvas with Firstname, lastname as textbox.city as list.vihicle as checkbox.Gender as radio button.
#There will be one save button and one refresh button
from tkinter import *
import tkinter
master= Tk()
Label(master,text='first name').grid(row=0)
Label(master,text='last name').grid(row=1)
e1=Entry(master)
e2=Entry(master)
e1.grid(row=0,column=1)
e2.grid(row=1,column=1)
Label(master,text='City').grid(row=2)
Lb=Listbox(master)
Lb.insert(1,'Mirganj')
Lb.insert(2,'Gopalganj')
Lb.insert(3,'Varanasi')
Lb.insert(4,'Delhi')
Lb.insert(5,'Kota')
Lb.insert(6,'Kolkata')
Lb.grid(row=3,column=1)
Label(master,text='Vehicle').grid(row=4)
CheckVar1=IntVar()
C1=Checkbutton(master,text='Car',variable=CheckVar1).grid(row=5,sticky=W,column=1)
CheckVar2=IntVar()
C2=Checkbutton(master,text='Bike',variable=CheckVar2).grid(row=5,sticky=W,column=2)
Label(master,text='Gender').grid(row=6)
var=IntVar()
Radiobutton(master,text='Male',variable=var,value=1).grid(row=7,column=1)
Radiobutton(master,text='Female',variable=var,value=2).grid(row=7,column=2)
save=Button(master,text='Save',fg='Black')
save.grid(row=8,column=1)
refresh=Button(master,text='Refresh',fg='Black')
refresh.grid(row=8,column=2)
mainloop()
#Label properties
lb=label(top,text='Hello',font=('Arial Bold'),50)
#Button Properties
btn=Button(top,text='Click',bg='yellow',fg='black')
#Button click event
def clicked():
lb.configure(text='clicked')
btn=Button(top,text='Click',bg='yellow',fg='black',command=clicked)
#Bext Box properties
e1=Entry(top,width=20)
#Button Click Event regarding Text Box
def clicked():
lb.configure(text='clicked')
btn=Button(top,text='Click',bg='yellow',fg='black',command=clicked)
from tkinter import *
master=Tk()
master.title('test')
lb=Label(master,text='Hello')
lb.grid(column=0,row=1)
e1=Entry(master,width=20)
e1.grid(column=0,row=2)
def clicked():
lb.configure(text='clicked')
btn=Button(master,text='Click',command=clicked)
btn.grid(row=3,column=0)
mainloop()
from tkinter import *
master=Tk()
master.title('test')
lb=Label(master,text='Hello')
lb.grid(column=0,row=1)
e1=Entry(master,width=20)
e1.grid(column=0,row=2)
def clicked():
r='Welcome '+e1.get()
lb.configure(text=r)
btn=Button(master,text='Click',command=clicked)
btn.grid(row=3,column=0)
mainloop()
#combo box
from tkinter import *
from tkinter.ttk import *
master=Tk()
master.title('test')
combo=Combobox(master)
combo['values']=(1,10,20,30,40,'text')
combo.current(1)
combo.grid(row=0,column=0)
w=Spinbox(master,from_=0,to=10)
w.grid(row=1,column=0)
mainloop()
#spin box
from tkinter import *
from tkinter.ttk import *
master=Tk()
master.title('test')
w=Spinbox(master,from_=0,to=10)
w.grid(row=1,column=0)
mainloop()
#popup window
from tkinter import *
from tkinter import messagebox
master=Tk()
master.title('popup window')
def clicked():
messagebox.showinfo('title','message information')
btn=Button(master,text='Click',command=clicked)
btn.pack()
mainloop()
#popup window
from tkinter import *
from tkinter import messagebox
master=Tk()
master.title('popup window')
def click1():
messagebox.showinfo('title','message information')
btn1=Button(master,text='Click',command=click1)
btn1.grid(row=0,column=1)
def click2():
messagebox.showwarning('warning','beware')
btn2=Button(master,text='Click',command=click2)
btn2.grid(row=1,column=1)
def click3():
messagebox.showerror('error','wrong')
btn3=Button(master,text='Click',command=click3)
btn3.grid(row=2,column=1)
mainloop()
from tkinter import *
from tkinter import messagebox
master=Tk()
master.title('popup window')
res=messagebox.askquestion('1','what is C')
res=messagebox.askyesno('ans','yes/no')
res=messagebox.askyesnocancel('ans','Choice')
res=messagebox.askokcancel('2','Nope')
res=messagebox.askretrycancel('0','try')
mainloop()
#progressbar
from tkinter import *
from tkinter.ttk import Progressbar
from tkinter import ttk
master=Tk()
master.title('Progress Bar')
bar=Progressbar(master,length=300,style='black.Horizontal.TProgressbar')
bar['value']=70
bar.grid(row=0,column=1)
mainloop()
create a program to show a chessboard of 4*4 houses
from tkinter import *
master=Tk()
master.title('Chessboard')
for i in range(4):
for j in range(4):
if(i+j)%2==0:
Button(master,width=30,height=12,bg='black').grid(row=i,column=j)
else:
Button(master,width=30,height=12,bg='white').grid(row=i,column=j)
mainloop()
import xlwt
from xlwt import Workbook
wb=Workbook()
sheet1=wb.add_sheet('sheet1')
sheet1.write(1,0,'ISBT DEHRADUN')
sheet1.write(2,0,'SHASTRADHARA')
sheet1.write(3,0,'CLEMEN TOWN')
sheet1.write(4,0,'RAJPUR ROAD')
sheet1.write(5,0,'CLOCK TOWER')
sheet1.write(0,1,'ISBT DEHRADUN')
sheet1.write(0,2,'SHASTRADHARA')
sheet1.write(0,3,'CLEMEN TOWN')
sheet1.write(0,4,'RAJPUR ROAD')
sheet1.write(0,5,'CLOCK TOWER')
wb.save('xlwt example.xls')
file=open('testfile.txt','w')
file.write('Hello world\n')
file.write('Hello world\n')
file.write('Hello world\n')
file.write('Hello world\n')
file.write('Hello world\n')
file.write('Hello world\n')
file.close()
file=open('testfile.txt','r')
print(file.read())
file=open('testfile.txt','r')
print(file.read(4))
print(file.readline(3))
o/p
Hello world
Hello world
Hello world
Hello world
Hello world
Hello world
Hello w
orl
file=open('testfile.txt','r')
for line in file:
print(line)
o/p
Hello world
Hello world
Hello world
Hello world
Hello world
Hello world
#Regular Expression
import re
line='cats are smarter than dogs'
matchObj=re.match(r'(.*) are (.*) .*', line,re.M|re.I)
if matchObj:
print('matchObj.group() : ', matchObj.group())
print('matchObj.group(1) : ', matchObj.group(1))
print('matchObj.group(2) : ', matchObj.group(2))
else:
print('No Match!!')
searchObj=re.search(r'(.*) are (.*) .*', line,re.M|re.I)
if searchObj:
print('searchObj.group() : ', searchObj.group())
print('searchObj.group(1) : ', searchObj.group(1))
print('searchObj.group(2) : ', searchObj.group(2))
else:
print('Nothing Found!!')
o/p
matchObj.group() : cats are smarter than dogs
matchObj.group(1) : cats
matchObj.group(2) : smarter than
searchObj.group() : cats are smarter than dogs
searchObj.group(1) : cats
searchObj.group(2) : smarter than