簡體   English   中英

Tkinter 窗口未在 pycharm 中打開

[英]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 個重要的東西:

  • 按鈕位於 tkinter 庫內的 ttk.py 文件中: 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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM