python - Simplest way to open a file in tkinter -
Trying to create a GUI with an 'open file' button When I run the code shown below, the open file dialogue opens directly, and when I press the button, how do I do it? Is it an easy way to decide that using classes is not included? (I currently do not know anything about classrooms and are working on time-pressing projects)
to tkinter import * interface = Tk () def openfile (): return Filedog.askopenfilename () button = ttk.Button (interface, text = "open", command = openfile ()) button. The grid (column = 1, line = 1) interface.mainloup ()
code < Code> openfile function is passing the return value of the call, not just the function. Call the function by removing the trunking ()
, which causes the call.
Ticker Import Import from Tiketter Import to Ticketer Import FileAlage Interface = TC () DEF OpenFile (): Return fileialog.askopenfilename () button = ttk.Button (interface, text = "Open", Command = openfile) #and Lt; ------ button.grid (column = 1, line = 1) interface. Menloof ()
Comments
Post a Comment