Fah*_*lis -1 python ubuntu tk-toolkit tkinter python-3.x
我正在ubuntu上用python编写程序,但是由于几天的时间,我遇到了这个非常恼人的问题,
Traceback (most recent call last):
File "/home/tansen/Documents/python2/button25_01JanV1.py", line 1, in <module>
import Tkinter,ttk
File "/home/tansen/Documents/python2/Tkinter.py", line 1, in <module>
from Tkinter import Tk, Label, Button
ImportError: cannot import name 'Tk'
Run Code Online (Sandbox Code Playgroud)
在此程序运行正常之前,我成功运行了多个时间程序
import tkinter.ttk
from tkinter import *
def viewFile():
pass
if __name__ == '__main__':
root = Tk()
step = LabelFrame(root,text="FILE MANAGER", font = "Arial 20 bold italic")
step.grid(row=1, columnspan=7, sticky='W',padx=100, pady=5, ipadx=130, ipady=25)
Button(step, text="OpenFile", font = "Arial 8 bold italic", activebackground="turquoise", width=30, height=5, command=viewFile).grid (row= 6, column =3)
Button(step, text="Exit", font = "Arial 8 bold italic", activebackground="turquoise", width=20, height=5, command=root.quit).grid (row= 6, column =5)
tex = Text(master=root) # TextBox For Displaying File Information
scr=Scrollbar(root,orient =VERTICAL,command=tex.yview)
scr.grid(row=8, column=2, rowspan=15, columnspan=1, sticky=NS)
tex.grid(row=8, column=1, sticky=E)
tex.config(yscrollcommand=scr.set,font=('Arial', 8, 'bold', 'italic'))
root.mainloop()
Run Code Online (Sandbox Code Playgroud)
根据专家的建议,我将文件Tkinter.py重命名,并将大写字母从“ T”更改为“ t”。之后,我的程序成功运行,但是又创建了另一个问题。按下退出按钮不起作用。

您能帮忙成功摆脱这一问题吗?
您Tkinter.py在同一目录中调用了文件,将其重命名并删除.pyc
/home/tansen/Documents/python2/Tkinter.py <- importing from this not the module
Run Code Online (Sandbox Code Playgroud)
您还使用python 2的Tkinter的import语法,请使用:
from tkinter import ttk, Text, Button, LabelFrame, VERTICAL, E, NS, Scrollbar, Tk
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4874 次 |
| 最近记录: |