代码不使用VS Codium,但使用VSCode

2024-10-03 19:27:49 发布

您现在位置:Python中文网/ 问答频道 /正文

我有这个密码

from tkinter import *
fenetre = Tk()
fenetre.mainloop()

他们不使用VSCodium,但可以很好地使用VSCode。 我只是在这两个版本上都添加了微软的扩展名“Python”,没有更多,也没有更少

有人知道为什么? 我个人更喜欢使用Codium

从VSCodium启动时,我进入了终端:

andres@andres-linux:~$ /usr/bin/python3 /home/andres/Bureau/CoursEPSI/Python/hello.py
Traceback (most recent call last):
  File "/home/andres/Bureau/CoursEPSI/Python/hello.py", line 1, in <module>
    from tkinter import *
  File "/home/andres/Bureau/CoursEPSI/Python/tkinter.py", line 3, in <module>
    fenetre = tk()
NameError: name 'tk' is not defined

使用VSCode,没有问题,它会打开一个窗口


Tags: infrompyimporthellohometkinterline
1条回答
网友
1楼 · 发布于 2024-10-03 19:27:49

试试这个

import tkinter
fenetre =tkinter.Tk()
fenetre.mainloop()

另外,在仔细查看了错误行之后

File "/home/andres/Bureau/CoursEPSI/Python/hello.py", line 1, in <module>
    from tkinter import *
File "/home/andres/Bureau/CoursEPSI/Python/tkinter.py", line 3, in <module>
    fenetre = tk()

我认为您需要将tk更改为Tk,即fenetre = tk()更改为fenetre = Tk()

相关问题 更多 >