Skip to content

Commit 52926af

Browse files
committed
exam updated
1 parent 9a25b39 commit 52926af

18 files changed

+232
-1
lines changed

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
# Ignore databaseUpdate.key file
22
databaseUpdate.key
33
TKInterface.key
4-
python_tutorial.pdf
4+
python_tutorial.pdf
5+
File Handling.ppt
6+
database update.ppt
7+
TKInterface.ppt

GUI Programming/1. Intro.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import tkinter
2+
top = tkinter.Tk()
3+
top.title("Hello World")
4+
5+
top.mainloop()

GUI Programming/10. Message.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
from tkinter import *
2+
3+
root = Tk()
4+
5+
L1 = Message(root, text="Hello World")
6+
L1.pack()
7+
8+
root.mainloop()

GUI Programming/11. RadioButton.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
from tkinter import *
2+
3+
def sel():
4+
selection = "You selected the option " + str(var.get())
5+
label.config(text = selection)
6+
7+
root = Tk()
8+
9+
var = IntVar()
10+
R1 = Radiobutton(root, text="Option 1", variable=var, value=1, command=sel)
11+
R1.pack( anchor = W )
12+
R2 = Radiobutton(root, text="Option 2", variable=var, value=2, command=sel)
13+
R2.pack( anchor = W )
14+
R3 = Radiobutton(root, text="Option 3", variable=var, value=3, command=sel)
15+
R3.pack( anchor = W)
16+
17+
label = Label(root)
18+
label.pack()
19+
root.mainloop()

GUI Programming/12. Scale.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
from tkinter import *
2+
def sel():
3+
selection = "Value = " + str(var.get())
4+
label.config(text = selection)
5+
6+
root = Tk()
7+
var = DoubleVar()
8+
scale = Scale( root, variable = var )
9+
scale.pack(anchor=CENTER)
10+
11+
button = Button(root, text="Get Scale Value", command=sel)
12+
button.pack(anchor=CENTER)
13+
14+
label = Label(root)
15+
label.pack()
16+
root.mainloop()

GUI Programming/2. Button.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
from tkinter import *
2+
from tkinter import messagebox
3+
top = Tk()
4+
top.geometry("500x500")
5+
def helloCallBack():
6+
messagebox.showinfo( "Hello Python", "Hello World2")
7+
B = Button(top, text ="Hello", command = helloCallBack)
8+
B.pack()
9+
top.mainloop()

GUI Programming/3. Canvas.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
from tkinter import *
2+
from tkinter import messagebox
3+
top = Tk()
4+
C = Canvas(top, bg = "blue", height = 250, width = 300)
5+
6+
coord = 10, 50, 240, 210
7+
arc = C.create_arc(coord, start = 0, extent = 290, fill = "red")
8+
9+
C.pack()
10+
top.mainloop()

GUI Programming/4. CheckBox.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
from tkinter import *
2+
3+
top = Tk()
4+
CheckVar1 = IntVar()
5+
CheckVar2 = IntVar()
6+
C1 = Checkbutton(top, text = "Option 1", variable = CheckVar1, onvalue = 1, offvalue = 0, height=5, width = 20)
7+
C2 = Checkbutton(top, text = "Option 2", variable = CheckVar2, onvalue = 1, offvalue = 0, height=5, width = 20)
8+
C1.pack()
9+
C2.pack()
10+
top.mainloop()

GUI Programming/5. Entry.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
from tkinter import *
2+
3+
top = Tk()
4+
5+
L1 = Label(top, text="User Name")
6+
L1.grid(row=0, column=0)
7+
L2 = Label(top, text="Password")
8+
L2.grid(row=1, column=0)
9+
10+
E1 = Entry(top, bd=5)
11+
E1.grid(row=0, column=1)
12+
E2 = Entry(top, bd=5)
13+
E2.grid(row=1, column=1)
14+
15+
top.mainloop()

GUI Programming/6. Frame.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
from tkinter import *
2+
3+
root = Tk()
4+
frame = Frame(root)
5+
frame.pack()
6+
7+
bottomframe = Frame(root)
8+
bottomframe.pack( side = BOTTOM )
9+
10+
redbutton = Button(frame, text="Red", fg="red")
11+
redbutton.pack( side = LEFT)
12+
13+
greenbutton = Button(frame, text="Brown", fg="brown")
14+
greenbutton.pack( side = LEFT )
15+
16+
bluebutton = Button(frame, text="Blue", fg="blue")
17+
bluebutton.pack( side = LEFT )
18+
19+
blackbutton = Button(bottomframe, text="Black", fg="black")
20+
blackbutton.pack( side = BOTTOM)
21+
22+
root.mainloop()

GUI Programming/7. Label.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
from tkinter import *
2+
root = Tk()
3+
4+
L = Label(root, text="Hello World")
5+
L.pack()
6+
7+
root.mainloop()

GUI Programming/8. ListBox.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
from tkinter import *
2+
3+
top = Tk()
4+
5+
L1 = Listbox(top)
6+
L1.insert(1, "1. Python")
7+
L1.insert(2, "2. Java")
8+
L1.insert(3, "3. C++")
9+
10+
L1.pack()
11+
top.mainloop()

GUI Programming/9. MenuButton.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
from tkinter import *
2+
3+
top = Tk()
4+
mb= Menubutton ( top, text="condiments" )
5+
mb.grid()
6+
mb.menu = Menu ( mb, tearoff = 0 )
7+
mb["menu"] = mb.menu
8+
9+
mayoVar = IntVar()
10+
ketchVar = IntVar()
11+
mb.menu.add_checkbutton (label="mayo", variable=mayoVar)
12+
mb.menu.add_checkbutton (label="ketchup", variable=ketchVar)
13+
mb.pack()
14+
top.mainloop()

chart.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import tkinter as tk
2+
3+
# Sample data for the bar chart (you can replace this with user-provided data)
4+
data = [("Minecraft", 238), ("G.Theft Auto V", 185), ("Tetris (EA)", 100), ("Wii Sports", 82.9), ("PUBG", 75)]
5+
6+
# Constants for chart dimensions
7+
CANVAS_WIDTH = 400
8+
CANVAS_HEIGHT = 300
9+
BAR_WIDTH = 55
10+
BAR_SPACING = 20
11+
CHART_TOP_MARGIN = 30
12+
13+
def draw_bar_chart(canvas, data):
14+
max_value = max(data, key=lambda item: item[1])[1]
15+
16+
# Calculate scaling factor to fit data within the canvas
17+
scale = (CANVAS_HEIGHT - CHART_TOP_MARGIN) / max_value
18+
19+
x = BAR_SPACING
20+
21+
for category, value in data:
22+
bar_height = value * scale
23+
canvas.create_rectangle(
24+
x, CANVAS_HEIGHT - bar_height, x + BAR_WIDTH, CANVAS_HEIGHT,
25+
fill="blue", outline="black"
26+
)
27+
canvas.create_text(
28+
x + BAR_WIDTH // 2, CANVAS_HEIGHT - bar_height - 10, text=category
29+
)
30+
x += BAR_WIDTH + BAR_SPACING
31+
32+
root = tk.Tk()
33+
root.title("5 best-selling video games")
34+
35+
canvas = tk.Canvas(root, width=CANVAS_WIDTH, height=CANVAS_HEIGHT, bg="white")
36+
canvas.pack()
37+
38+
# Draw the bar chart on the canvas
39+
draw_bar_chart(canvas, data)
40+
41+
root.mainloop()

l.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
i = 0
2+
while i < 5:
3+
print (i, end=' ')
4+
i += 1
5+
if 1%2 == 0:
6+
break
7+
else:
8+
print(0)

m.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
str1 = 'hello'
2+
str2 = ','
3+
str3 = 'world'
4+
str4=str1+str2+str3
5+
str4[-5::-1]

multithreading.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import _thread
2+
import time
3+
4+
# Define a function for the thread
5+
def print_time( threadName, delay):
6+
count = 0
7+
while count < 5:
8+
time.sleep(delay)
9+
count += 1
10+
print ("%s: %s" % ( threadName, time.ctime(time.time()) ))
11+
12+
# Create two threads as follows
13+
try:
14+
thread.start_new_thread( print_time, ("Thread-1", 2, ) )
15+
thread.start_new_thread( print_time, ("Thread-2", 4, ) )
16+
except:
17+
print ("Error: unable to start thread")
18+
19+
while 1:
20+
pass

temp.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
i = 0
2+
while i ‹ 5:
3+
print (i, end=' ')
4+
i += 1
5+
if 1%2 == 0:
6+
break
7+
else:
8+
print(0)

0 commit comments

Comments
 (0)