简体   繁体   English

打开文件按钮-Python Tkinter

[英]Open File Button - Python Tkinter

I am having a problem where I cannot link my open Button to the "open" command, help please! 我遇到无法将打开按钮链接到“打开”命令的问题,请帮忙!

Error= fileName = tkFileDialog.askopenfilename()
NameError: global name 'tkFileDialog' is not defined

What I have: 我有的:

from Tkinter import *
from tkFileDialog   import askopenfilename

frm = Frame(parent)
frm.pack(fill=X)
Button(frm, text=' Browse  ',   command=self.getFileName).pack(side=LEFT)

def getFileName(self):
    fileName = tkFileDialog.askopenfilename()
    iconEntry.insert(0, fileName)

SimpleEditor().mainloop()   

rather than 而不是

from tkFileDialog import askopenfilename

you probably just want 你可能只想

import tkFileDialog

yeah. 是的 Since you are already doing "tkFileDialog.askopenfilename()", you don't need to do this "from tkFileDialog import askopenfilename" 由于您已经在执行“ tkFileDialog.askopenfilename()”,因此不需要“从tkFileDialog import askopenfilename”执行此操作

Simply, import tkFileDialog will do. 只需导入tkFileDialog就可以。

instead of using from tkFileDialog import askopenfilename 而不是使用from tkFileDialog import askopenfilename

use import Tkinter.Filedialog as tkFiledialog 使用import Tkinter.Filedialog as tkFiledialog

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM