简体   繁体   English

使用python Tkinter调用由askopenfilename命令确定的值

[英]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.

相关问题 Python tkinter askopenfilename 没有响应 - Python tkinter askopenfilename not responding 如何使用 tkinter askopenfilename 或其他命令获取文件路径? - How to get a file path using tkinter askopenfilename or other command? Python tkinter askopenfilename() 没有打开和响应 - Python tkinter askopenfilename() not opening and responding 在 Tkinter / Python 中使用 askopenfilename 打开 KNOWNFOLDERID - open KNOWNFOLDERID with askopenfilename in Tkinter / Python [mac Monterey][Python 3.10.4][tkinter 8.6] 重复创建 window 时调用 tkinter askOpenfilename 崩溃 - [mac Monterey][Python 3.10.4][tkinter 8.6] Calling tkinter askOpenfilename crashes when repeatedly creating a window 在Mac上的Python中使用askopenfilename - Using askopenfilename in Python on Mac Python tkinter askopenfilename 对我有用,现在没有响应 - Python tkinter askopenfilename was working for me and is now not responding 使用askopenfilename的“ tkinter TclError:文件类型错误” - “tkinter TclError: bad file type” using askopenfilename 如何使用 filedialog.askopenfilename() 从 TkInter Python 3 中的另一种方法获取所选文件的路径 - How to get the route of selected file using filedialog.askopenfilename() from another method in TkInter Python 3 如何打开与Python 2和Python 3兼容的Tkinter askopenfilename对话框 - How to open a Tkinter askopenfilename dialog compatible with Python 2 and Python 3
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM