tkinter - How do I change a label's text to a file name on button press in Python? -


how can change text of label_1 equal file select in browse_for_file_1? i've been trying various methods can't seem gui update. think may because it's in frame within frame?

import tkinter tk import tkfiledialog  root = tk.tk()  #frames frame_1 = tk.frame(root) frame_1.pack()  def browse_for_file_1():     file_name_1 = tkfiledialog.askopenfilename(parent=root,title='open 1st file')     print file_name_1     label_1.config(text=file_name_1)     root.update()    #browse 1 browse_button_1 = tk.button(frame_1, text='browse 1st file', width=25, command=browse_for_file_1).pack(side=tk.left, pady=10, padx=10) label_1 = tk.label(frame_1, fg="red", text="no file selected.") label_1.pack(side=tk.right, pady=10, padx=10)  #quit button quit = tk.button(root, text='quit', width=25, fg="red", command=root.destroy).pack(pady=10, padx=10)  root.title("zero usage") root.mainloop() 

change call:

browse_button_1 = tk.button(frame_1, text='browse 1st file', width=25, command=lambda:browse_for_file_1(label_1)).pack(side=tk.left, pady=10, padx=10)

then function can be:

def browse_for_file_1(label_1):   file_name_1 = tkfiledialog.askopenfilename(parent=root,title='open 1st file')   label_1.config(text=file_name_1)   # or label_1.config({'text':file_name_1}) 

Comments

Popular posts from this blog

Email notification in google apps script -

c++ - Difference between pre and post decrement in recursive function argument -

javascript - IE11 incompatibility with jQuery's 'readonly'? -