Untitled

 avatar
unknown
plain_text
5 months ago
1.9 kB
5
Indexable
import tkinter as tk
from tkinter import ttk

class App:
    def __init__(self):
        # Tạo cửa sổ chính
        self.root = tk.Tk()
        self.root.title("Giao diện với 2 tab")
        self.root.geometry("400x300")

        # Đặt font mặc định là Times New Roman
        style = ttk.Style()
        style.configure('TNotebook', font=('Times New Roman', 12))
        style.configure('TNotebook.Tab', font=('Times New Roman', 12))

        # Tạo widget Notebook (dùng cho Tab)
        self.notebook = ttk.Notebook(self.root)

        # Tạo các frame cho từng tab
        self.tab1 = ttk.Frame(self.notebook)
        self.tab2 = ttk.Frame(self.notebook)

        # Thêm các frame vào notebook
        self.notebook.add(self.tab1, text="Tab 1")
        self.notebook.add(self.tab2, text="Tab 2")

        # Hiển thị Notebook
        self.notebook.pack(expand=True, fill="both")

        # Nội dung cho Tab 1
        self.label1 = tk.Label(self.tab1, text="Đây là nội dung của Tab 1.", font=("Times New Roman", 14))
        self.label1.pack(pady=20)
        self.entry1 = tk.Entry(self.tab1, font=("Times New Roman", 12))
        self.entry1.pack(pady=10)

        # Nội dung cho Tab 2
        self.label2 = tk.Label(self.tab2, text="Đây là nội dung của Tab 2.", font=("Times New Roman", 14))
        self.label2.pack(pady=20)
        self.button2 = tk.Button(self.tab2, text="Nhấn vào tôi!", font=("Times New Roman", 12), command=self.on_button_click)
        self.button2.pack(pady=10)

    def on_button_click(self):
        # Hàm xử lý khi nút bấm được nhấn
        print("Bạn đã nhấn nút!")

    def run(self):
        # Bắt đầu vòng lặp giao diện
        self.root.mainloop()


# Chạy ứng dụng
if __name__ == "__main__":
    app = App()  # Tạo đối tượng App
    app.run()    # Chạy ứng dụng
Editor is loading...
Leave a Comment