Computer >> Hướng Dẫn Máy Tính >  >> Lập Trình >> Python

Tạo hộp thoại nhắc (prompt dialog) dùng Tkinter

Hộp thoại thông báo người dùng thực hiện thao tác. Quen dialog box tương tác nhiều lần. Trong Tkinter, tạo mọi loại dialog: Message, User Interaction, Single Value Entry, File chooser. Tkinter có package tích hợp: messagebox, simpledialog, filedialog, colorchooser.

Ví dụ

Tạo message box yêu cầu chọn tùy chọn.

#Import tkinter library
from tkinter import *
from tkinter import messagebox
#Tạo instance Tkinter frame
win= Tk()
#Đặt geometry
win.geometry("750x250")
answer = messagebox.askyesno("Question","Do you like Python Tkinter?")
#Tạo Label
Label(win, text=answer, font= ('Georgia 20 bold')).pack()
win.mainloop()

Kết quả

Chạy mã hiển thị prompt dialog. Chọn tùy chọn hiển thị giá trị Boolean: Yes (1) hoặc No (0).

Tạo hộp thoại nhắc (prompt dialog) dùng Tkinter

Bấm Yes/No cập nhật cửa sổ Tkinter giá trị 1/0.