3-topshiriq Tkinter bilan kirish maydonini yaratish ya’ni login parol terish oynasi. Tkinter yordamida to’rtburchak, aylana chizish Tkinterda kalkulyator yaratish Tkinterda arifmetik amallarni bajaradigan oyna yarating


Download 1.07 Mb.
Sana17.06.2023
Hajmi1.07 Mb.
#1523081
Bog'liq
3-topshiriq Narzikulov


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.

import tkinter as tk


def check_login():
username = username_entry.get()
password = password_entry.get()
if username == "Narzikulov" and password == "AC0310828":
message_label.config(text="Login muvaffaqiyatli amalga oshirildi.")
else:
message_label.config(text="Login yoki maxfiy so'z noto'g'ri.")
root = tk.Tk()
root.title("Login oynasi")
# Username qatori
username_label = tk.Label(root, text="Login")
username_label.pack()
username_entry = tk.Entry(root)
username_entry.pack()
# Password qatori
password_label = tk.Label(root, text="Maxfiy so'z")
password_label.pack()
password_entry = tk.Entry(root, show="*")
password_entry.pack()
# Login tugmasi
login_button = tk.Button(root, text="Login", command=check_login)
login_button.pack()
# Xabarlar qismi
message_label = tk.Label(root, text="")
message_label.pack()
# Oyna
root.mainloop()




2. Tkinter yordamida to’rtburchak, aylana chizish
#to`rtburchak
i mport tkinter as tk

root = tk.Tk()


canvas = tk.Canvas(root, width=200, height=200)
canvas.pack()
x1 = 50
y1 = 50
x2 = 150
y2 = 150
canvas.create_rectangle(x1, y1, x2, y2)
r oot.mainloop()
#Aylana
import tkinter as tk
root = tk.Tk()
canvas = tk.Canvas(root, width=200, height=200)
canvas.pack()
x1 = 50
y1 = 50
x2 = 150
y2 = 150
canvas.create_oval(x1, y1, x2, y2)
root.mainloop()


3va4.Tkinterda kalkulyator yaratish va Tkinterda arifmetik amallarni bajaradigan oyna yaratish.
import tkinter as tk
class Calculator:
def __init__(self, root):
self.root = root
root.title("Kalkulyator")
self.entry = tk.Entry(root, width=40, borderwidth=5)
self.entry.grid(row=0, column=0, columnspan=4, padx=5, pady=5)
# Kalkulyator tugmalari
b1 = self.create_button("1", 1, 0)
b2 = self.create_button("2", 1, 1)
b3 = self.create_button("3", 1, 2)
b4 = self.create_button("4", 2, 0)
b5 = self.create_button("5", 2, 1)
b6 = self.create_button("6", 2, 2)
b7 = self.create_button("7", 3, 0)
b8 = self.create_button("8", 3, 1)
b9 = self.create_button("9", 3, 2)
b0 = self.create_button("0", 4, 1)
b_plus = self.create_button("+", 1, 3)
b_minus = self.create_button("-", 2, 3)
b_mul = self.create_button("*", 3, 3)
b_div = self.create_button("/", 4, 3)
b_clear = self.create_button("C", 4, 0)
b_equal = self.create_button("=", 4, 2)
# Kalkulyator tugmalarini rost joyga joylash
buttons = [b1, b2, b3, b4, b5, b6, b7, b8, b9, b0, b_plus, b_minus, b_mul, b_div, b_clear, b_equal]
for button in buttons:
button.grid(sticky="nsew", padx=5, pady=5)
# Kalkulyator tugmasini yaratish
def create_button(self, text, row, column):
button = tk.Button(self.root, text=text, font=("Arial", 16), command=lambda: self.button_press(text))
return button.grid(row=row, column=column)
# Kalkulyator tugmalari bosilganda qanday amal bajarilishi kerakligini aniqlash
def button_press(self, text):
if text == "C":
self.entry.delete(0, tk.END)
elif text == "=":
try:
result = eval(self.entry.get())
self.entry.delete(0, tk.END)
self.entry.insert(0, result)
except:
self.entry.delete(0, tk.END)
self.entry.insert(0, "ERROR")
else:
self.entry.insert(tk.END, text)
# Kalkulyator obyektini yarating
root = tk.Tk()
calc = Calculator(root)
root.mainloop()
5.Tkinterda vaqtni ko’rsatish uchun soat yarating.

import tkinter as tk


from datetime import datetime

class Clock(tk.Frame):


def __init__(self, master=None):
super().__init__(master)
self.master = master
self.pack()
self.create_widgets()
self.tick()

def create_widgets(self):


self.time_display = tk.Label(self, text="", font=('Arial', 20))
self.time_display.pack(pady=10)

def tick(self):


current_time = datetime.now().time()
formatted_time = round(current_time.hour%12 + current_time.minute/60 + current_time.second/3600, 2)
self.time_display.config(text=f"{formatted_time} ")
self.after(1000, self.tick)

if __name__ == '__main__':


root = tk.Tk()
root.title("Clock")
clock = Clock(root)
root.mainloop()



Download 1.07 Mb.

Do'stlaringiz bilan baham:




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