[英]calling the value determined by the askopenfilename command using python Tkinter
Hi I've made a simple GUI that contains a browse button which uses askopenfilename
: 嗨,我制作了一个简单的GUI,其中包含一个使用askopenfilename
的浏览按钮:
browsebutton = Button(mGui,text='Browse',command=askopenfilename)
browsebutton.place(x=400,y=50)
I have been trying to print this file name to a text file as part of a larger script, I have tried many different strategies, my last attempt was this: 我一直在尝试将此文件名打印到文本文件中,作为更大脚本的一部分,我尝试了许多不同的策略,最后一次尝试是:
conf.write("receptor="'invoke(browsebutton)'"\n")
I'm having touble finding out how to call this function, I just started programming and I have tried multiple strategies but none seem to work. 我在寻找如何调用此函数的过程中遇到麻烦,我刚刚开始编程,并且尝试了多种策略,但似乎没有一个起作用。 I am using Python 2.5, thank you for your help. 我正在使用Python 2.5,谢谢您的帮助。 -Paul 保罗
Create function with askopenfilename()
and assign it to button 使用askopenfilename()
创建函数并将其分配给按钮
import Tkinter as tk
from tkFileDialog import askopenfilename
def some_function():
filename = askopenfilename()
if filename:
print "selected:", filename
else:
print "file not selected"
mGui = tk.Tk()
browsebutton = tk.Button(mGui,text='Browse',command=some_function)
browsebutton.pack()
mGui.mainloop()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.