Home > other >  Rookie help simple question!
Rookie help simple question!

Time:09-25

 the from tkinter. Filedialog import askopenfilename 
The import tkinter
The import OS

Tkinter. Tk (). The geometry (" 800 x600 + 200 + 20 ") # frame layout (length x width + x + y)

B=tkinter. Button (text="Button")
P. lace (x=20, y=20)

Default_dir=r "C: \ Users \ lenovo \ Desktop" # set the default open directory
Def WWW (event) :
Fn=askopenfilename (title="select files", initialdir=(OS) path) expanduser (default_dir)))
Print (fn)
Return fn

B.b ind (" & lt; Button 1 & gt;" , the WWW)
# print (WWW ()) has been an error here, not use return
Tkinter. Mainloop ()

I just started studying Python, there are two simple questions to ask you a great god, and def WWW (event) inside the parameters of the event is what mean?
And I want to get the inside of the def parameter fn results, how to put the inside of the fn transfer results come out?
I want to return to return no, other methods don't understand, please directly,

CodePudding user response:

Widget events triggered controls

The x, y, position the mouse from the top left corner of the form (coordinates)

X_root, x_y mouse from the top left corner of the screen position (coordinates)

Char keyboard events corresponding character code

Keysym keyboard events corresponds to the string

Keycode keyboard events corresponding key code

Num mouse events corresponding key code

Width, height control of the new size

Type the event type
Use event. The type can obtain corresponding event type, other similarly,

Secondly, function WWW () need parameter, so when you use the print give WWW () a parameter should be ok,

CodePudding user response:

reference 1/f, Smart - Space reply:
widget events triggered controls

The x, y, position the mouse from the top left corner of the form (coordinates)

X_root, x_y mouse from the top left corner of the screen position (coordinates)

Char keyboard events corresponding character code

Keysym keyboard events corresponds to the string

Keycode keyboard events corresponding key code

Num mouse events corresponding key code

Width, height control of the new size

Type the event type
Use event. The type can obtain corresponding event type, other similarly,

Secondly, function WWW () parameters, so you give WWW when use the print () a parameter should be ok,


The great god, can you tell me how to change directly, please? Or I belong to the novice level, see theory not only know the change! Could you please help me to change the how don't go wrong?

CodePudding user response:

 


The from tkinter. Filedialog import askopenfilename
The import tkinter
The import OS

Tkinter. Tk (). The geometry (" 800 x600 + 200 + 20 ") # frame layout (length x width + x + y)

B=tkinter. Button (text="Button")
P. lace (x=20, y=20)

Default_dir=r "C: \ Users \ lenovo \ Desktop" # set the default open directory

You_choice_file='

Def WWW (event) :
Fn=askopenfilename (title="select files", initialdir=(OS) path) expanduser (default_dir)))
Print (fn, 'want to do is do not need to return here')



B.b ind (" & lt; Enter>" , the WWW)
Use buuton - # 1, button will not recover, better use Enter
# # print (WWW ()) has been an error here, not use return
# window start, what to do, is to call the corresponding function through events,
Tkinter. Mainloop ()



CodePudding user response:

Thank you very much for your answer, I still want to know how to put the fn in the def function parameter values passed out? Because I do foundation is very poor!

CodePudding user response:

You must first understand the sequence of program structure difference structure and event-driven programs,




In tk program, tkinter. Mainloop (), all the things to the main thread, any operation and relevant events,


On how you put the fn in the def function parameter values passed out this problem, where do you want to make sure of the value to pass, is ,

If you want to pass this value to another form, and then through the message mechanism, if you want to print the values, has in my code, if it is to save to the database, or written to a file, then print statement, combined with the corresponding code,
  • Related