我是编程新手,并且正在使用pycharm作为我的IDE。
import _tkinter # If this fails your Python may not be configured for Tk
ModuleNotFoundError: No module named '_tkinter'
不确定我为什么收到此错误,我也安装了Tk库,仍然收到错误。我正在使用Mac。
[如果您使用的是python3,请使用
import tkinter
好,如果您使用的是python 3.8,则在安装安装程序中,它具有以下选择:
如果这不能解决您的问题,请阅读python官方文档:IDLE and tkinter with Tcl/Tk on macOS。
要使用世界创建窗口,请使用此
from tkinter import *
from tkinter.ttk import * # importing themed widget library
root = Tk() # creating the root master application object
label = Label(root, text="Hello World") # simple text: hello world
label.pack() #Places label into its parent
root.mainloop() # running the mainloop