我什麼時候需要在 Tkinter 應用程式中呼叫主迴圈?
Python Tkinter 是一個用於開發基於 GUI 的特色且實用的應用程式的標準庫。每當我們執行我們的應用程式時,它都會顯示一個包含一些小部件和一個標題欄的通用視窗。mainloop() 方法負責執行指令碼和顯示輸出視窗。但是,mainloop() 意味著在使用者仍停留在視窗中後它不會自動終止。每當使用者終止程式時,它都會自動關閉。每當程式開始執行時都會呼叫 mainloop() 方法。
示例
# Import the required libraries
from tkinter import *
# Create an instance of tkinter frame
win = Tk()
win.geometry("700x350")
# Add a Label widget
Label(win, text="This is a New Line Text", font= ('Times New Roman', 18,'bold')).pack(pady= 40)
win.mainloop()輸出
執行以上程式碼將會顯示一個帶有文字訊息的新視窗。
廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP