[英]Tkinter window not opening in pycharm
我正在使用 tkinter 在 pycharm 中編輯代碼,但窗口沒有打開。 有人可以幫忙嗎? `
import tkinter
window = tkinter.Tk()
button = tkinter.Button(window, text="Do not press this button! >:-(", width=40)
button.pack(padx=10, pady=10)
`
我試着檢查我的腳本是否有錯誤但沒有
這與 Pycharm 無關,而是與 tkinter 庫以及如何使用它有關。
您缺少 2 個重要的東西:
from tkinter import ttk
mainloop
執行整個腳本試試這個:
import tkinter
from tkinter import ttk # Import ttk file from tkinter library
window = tkinter.Tk()
window.title("Coolest title ever written")
button = ttk.Button(window, text="Do not press this button! >:-(", width=40) # Use Button from the import ttk file
button.pack(padx=10, pady=10)
window.mainloop() # Execute the whole script
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.