Guruh talabasi: Tovboyev Fazliddin 3-topshiriq


Download 0.55 Mb.
Sana06.10.2023
Hajmi0.55 Mb.
#1693242
Bog'liq
3-topshiriq


121-20 guruh talabasi: Tovboyev Fazliddin
3-topshiriq

1. Tkinter bilan kirish maydonini yaratish ya’ni login parol terish oynasi.


2. Tkinter yordamida to’rtburchak, aylana chizish
3. Tkinterda kalkulyator yaratish
4. Tkinterda arifmetik amallarni bajaradigan oyna yarating.
5. Tkinterda vaqtni ko’rsatish uchun soat yarating.

Javoblar:
1.Tkinter bilan kirish maydonini yaratish ya’ni login parol terish oynasi.
Dastur kodi:
import tkinter
from tkinter import messagebox
window=tkinter.Tk()
window.title("Login form")
window.geometry('350x350')
window.configure(bg='#0164B9')

def login():


username="programmer"
password="programmer_0130"
if username_entry.get()==username and password_entry.get()==password:
messagebox.showinfo(title="Login to'g'ri kiritildi",message="Siz muvofaqiyatli kirdingiz")
else:
messagebox.showerror(title="Hatolik qaytadan urinib ko'ring", message="Hatolik yuz berdi")

frame=tkinter.Frame(bg='#0164B9')

login_label=tkinter.Label(frame, text="Login", bg="#0164B9", fg="#FFFFFF", font=('Arial',30))
username_label=tkinter.Label(frame, text="Username",bg="#0164B9", fg="#FFFFFF", font=('Arial',16))
username_entry=tkinter.Entry(frame,bg="#333333", fg="#FFFFFF", font=('Arial',16))
password_entry=tkinter.Entry(frame, show="*",bg="#333333", fg="#FFFFFF", font=('Arial',16))
paswoed_label=tkinter.Label(frame,text="Password",bg="#0164B9", fg="#FFFFFF", font=('Arial',16))
login_button=tkinter.Button(frame, text="Login",bg="#0164B9", fg="#FFFFFF", font=('Arial',16), command=login)

login_label.grid(row=0, column=0, columnspan=2,sticky="news", pady=30)


username_label.grid(row=1, column=0)
username_entry.grid(row=1, column=1,pady=15)
paswoed_label.grid(row=2, column=0)
password_entry.grid(row=2, column=1, pady=15)
login_button.grid(row=3, column=0, columnspan=2, pady=30)

frame.pack()


window.mainloop()

Dasturdan natijasi:



2. Tkinter yordamida to’rtburchak, aylana chizish


Dastur kodi:
import tkinter as tk
window=tk.Tk()
window.geometry('600x400')
window.title('Canvas da ishlash')

canvas=tk.Canvas(window, bg='grey')


canvas.pack()

canvas.create_rectangle((20,20,100,200), fill='blue', width=6, outline='red')

canvas.create_oval((200, 20, 300,100), fill='green', width=6, outline='red')

def chizish(event):


x=event.x
y=event.y
canvas.create_oval((x-bs/4,y-bs/4,x+bs/2,y-bs/2,), fill='green', width=4)
bs=1
canvas.bind('', chizish)

window.mainloop()


Dastur natijasi:

3. Tkinterda kalkulyator yaratish
Dastur kodi:
import tkinter as tk
window = tk.Tk()
window.geometry('500x580')
window.title("Kalkulator")
window.resizable(False,False)
window.configure(bg="black")

def caculate(operation):


global formula
if operation=='C':
formula=''
elif operation=='del':
formula=formula[0:-1]
elif operation=='X^2':
formula=str(eval(formula)**2)
elif operation=='=':
formula=str(eval(formula))
else:
if formula=='0':
formula=''
formula+=operation
label_text.configure(text=formula)

formula='0'


label_text=tk.Label(text=formula,font=('Roboto',30,'bold'),bg='black',fg='white')
label_text.place(x=11, y=50)

buttons=['C','del','%','X^2','7','8','9','/','4','5','6','*','1','2','3','+','=','0','+/-','-']


x=18
y=140
for button in buttons:
get_lbl=lambda x=button:caculate(x)
tk.Button(text=button,bg="green",font=('Roboto',15), command=get_lbl).place(x=x,y=y,width=115,height=79)
x+=117
if x>400:
x=18
y+=81

window.mainloop()

Dastur tuzish jarayonidan video skrin:

4. Tkinterda arifmetik amallarni bajaradigan oyna yarating.
Dastur kodi:
import tkinter
from tkinter import messagebox
window=tkinter.Tk()
window.title("Arifmetik ammallar bajarish")
window.geometry('450x440')
window.configure(bg='#333333')

def qoshish():


son1=int(son_kirit1.get())
son2 = int(son_kirit2.get())
qoshish_son =son1+son2
label4.configure(text="{0}".format(qoshish_son))

def ayirish():


son1 = int(son_kirit1.get())
son2 = int(son_kirit2.get())
ayirish_son = son1 - son2
label4.configure(text="{0}".format(ayirish_son))

def bolish():


son1 = int(son_kirit1.get())
son2 = int(son_kirit2.get())
bolish_son = son1 / son2
label4.configure(text="{0}".format(bolish_son))

def kopaytirish():


son1 = int(son_kirit1.get())
son2 = int(son_kirit2.get())
kopaytirish_son = son1 * son2
label4.configure(text="{0}".format(kopaytirish_son))

frame=tkinter.Frame(bg='#333333')


label=tkinter.Label(frame, text="Arifmetik amallar",bg="#333333",fg='#FF3399',font=('Arial',20))
label1=tkinter.Label(frame, text="1-sonni kiriting:",bg="#333333",fg='#FF3399',font=('Arial',16))
label2=tkinter.Label(frame, text="2-sonni kiriting: ",bg="#333333",fg='#FF3399',font=('Arial',16))

son_kirit1=tkinter.Entry(frame,bg="#333333",fg='#FFFFFF',font=('Arial',16))


son_kirit2=tkinter.Entry(frame,bg="#333333",fg='#FFFFFF',font=('Arial',16))

qoshish_tugma=tkinter.Button(frame, text=" Qoshish",bg="#333333",fg='#FF3399',font=('Arial',10),command=qoshish)


ayirish_tugma=tkinter.Button(frame, text=" Ayirish",bg="#333333",fg='#FF3399',font=('Arial',10),command=ayirish)
bolish_tugma=tkinter.Button(frame, text=" Bolish",bg="#333333",fg='#FF3399',font=('Arial',10),command=bolish)
kopaytirish_tugma=tkinter.Button(frame, text=" Ko'paytirish",bg="#333333",fg='#FF3399',font=('Arial',10),command=kopaytirish)

label3=tkinter.Label(frame, text="Javob: ",bg="#333333",fg='#FF3399',font=('Arial',16))


label4=tkinter.Label(frame, text="0",bg="#333333",fg='#FF3399',font=('Arial',16))

label.grid(row=0, column=0, columnspan=2, pady=20)


label1.grid(row=1, column=0,pady=10)
label2.grid(row=2, column=0,pady=10)
label3.grid(row=3, column=1,pady=10)
label4.grid(row=4, column=1,pady=10)

son_kirit1.grid(row=1, column=1)


son_kirit2.grid(row=2, column=1)

qoshish_tugma.grid(row=3, column=0, columnspan=1,pady=5)


ayirish_tugma.grid(row=4, column=0, columnspan=1,pady=5)
bolish_tugma.grid(row=5, column=0, columnspan=1,pady=5)
kopaytirish_tugma.grid(row=6, column=0, columnspan=1,pady=5)

frame.pack()


window.mainloop()

5. Tkinterda vaqtni ko’rsatish uchun soat yarating.


Dastur kodi:
from tkinter import *
from tkinter.ttk import *
from time import strftime
root=Tk()
root.title("Fazliddin soati")
root.geometry('250x100')
root.configure(bg='black')

def time():


string=strftime('%H:%M:%S')
lbl.config(text=string)
lbl.after(1000,time)
lbl=Label(root,font=('colibri',40,'bold'),background='purple', foreground='white')
lbl.pack(anchor='center')
time()
mainloop()

Dasturdan video skrinlar:



Download 0.55 Mb.

Do'stlaringiz bilan baham:




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling