Home > other >  Python button calls the function problem
Python button calls the function problem

Time:09-23


Using the python tkinter module, probably is to use a button to open the window and running in child window function, but
I run the results did not return to the child window, only son serial number, which bosses please look for me, especially worry,



The import tkinter
The import tkinter. Messagebox
The import math
ABC (def) :
Root=tkinter. Tk ()
Root. Title (' hurricane wave of related parameter to the ')
Root. Geometry (' 600 x300 ')
VarVF=tkinter. StringVar ()
VarVF. Set (')
VarP0=tkinter. StringVar ()
VarP0. Set (')
Var theta equals tkinter. StringVar ()
Var theta. Set (' ')
# varf=tkinter. StringVar ()
# varf. Set (')
VarR=tkinter. StringVar ()
VarR. Set (')
VarHmax=tkinter. StringVar ()
VarHmax. Set (')
VarTmax=tkinter. StringVar ()
VarTmax. Set (')



# to create VF label and input text box
LabelVF=tkinter. Label (root, text='VF wind speed (m/s) :)
LabelVF. Place (x=10, y=50, width=140, height=20)
EntryVF=tkinter. Entry (root, textvariable=varVF)
EntryVF. Place (x=125, y=50, width=40, height=20)

# to create P0 label and input text box
LabelP0=tkinter. Label (root, text='P0 hurricane center air pressure (hpa) :')
LabelP0. Place (x=220, y=50, width=140, height=20)
EntryP0=tkinter. Entry (root, textvariable=varP0)
EntryP0. Place (x=355, y=50, width=40, height=20)

F # create coriolis force parameters TAB and input text box
# labelf=tkinter. Label (root, text='f (coriolis force parameters) :')
# labelf. Place (x=340, y=30, width=80, height=20)
# entryf=tkinter. Entry (root, textvariable=varf)
# entryf. Place (x=420, y=30, width=40, height=20)

# latitude to create a label and input text box
Label theta equals tkinter. Label (root, text='theta latitude () :')
Label theta. Place (x=440, y=50, width=80, height=20)
Entry theta equals tkinter. Entry (root, textvariable=var theta)
Entry theta. Place (x=515, y=50, width=40, height=20)




# create hurricane center to the distance of maximum wind speed R labels and text box
LabelR=tkinter. Label (root, text='R distance (km) :')
LabelR. Place (x=220, y=240, width=80, height=20)
EntryR=tkinter. Entry (root, textvariable=varR)
EntryR. Place (x=310, y=240, width=40, height=20)

# to create Hmax labels and text box
LabelHmax=tkinter. Label (root, text='high Hmax most big Bob (m) :')
LabelHmax. Place (x=80, y=200, width=140, height=20)
EntryHmax=tkinter. Entry (root, textvariable=varHmax)
EntryHmax. Place (x=220, y=200, width=40, height=20)

# to create Tmax labels and text box
LabelTmax=tkinter. Label (root, text='Tmax maximum wavelength cycle (s) :)
LabelTmax. Place (x=330, y=200, width=150, height=20)
EntryTmax=tkinter. Entry (root, textvariable=varTmax)
EntryTmax. Place (x=490, y=200, width=40, height=20)


Confirm (def) :
# confirmation button event handler
# get VF, P0, theta

VF=entryVF. The get ()
P0=entryP0. The get ()
Theta=entry theta. The get ()
# f=entryf. The get ()
# R=entryR. The get ()
Alpha=float (1.0)
# Δ P=760 - float (P0)/5
VF=float (VF)
Theta equals float (theta)
P0=float (P0)
Δ P=760 - P0 * 0.75
F=0.5235 * math. Sin (theta)
# f=0.525 * math. Sin (theta)
R=28.52 * math.h tanh (0.0873 * (theta - 28.0)) + 12.22 * math.h exp (33.86) (P0-1013.3)/VF * 3.6 + 37.22 + 0.2 *
F=float (f)
R=float (R)
Umax=float (0.447 * (14.5 * pow (Δ P, 1/2) - R * 0.31 * f)) # calculation on the surface of the 10 m elevation gradient wind speed m/s largest

If VF==0: # hurricane is stationary or mobile
UR=0.865 * Umax
Elif VF> 0:
UR=0.865 + 0.5 * * Umax VF
Hmax=float (5.03 * math. J exp (R * Δ P/4700) * (1 + 0.29 * alpha * VF/pow (UR, 1/2)))
Tmax=float (8.6 * math. J exp (R * Δ P/9400) * (1 + 0.145 * alpha * VF/pow (UR, 1/2)))
Print (Hmax)
Print (Tmax)
Print (R)
VarHmax. Set (Hmax)
VarTmax. Set (Tmax)
VarR. Set (R)



# to create button component, at the same time, the set up button event handler
ButtonOk=tkinter. Button (root, text='confirmed', fg="blue", the command=confirmation)
ButtonOk. Place (x=210, y=130, width=50, height=20)
# to cancel button event handler
Def cancel () :
# empty user input number
VarVF. Set (')
VarP0. Set (')
Var theta. Set (' ')
VarR. Set (')
VarHmax. Set (')
VarTmax. Set (')
ButtonCancel=tkinter. Button (root, text='cancel', fg="blue", the command=cancel)
ButtonCancel. Place (x=350, y=130, width=50, height=20)
# buttonOk. Destroy ()

Top. Destroy ()
# start message loop
Root. Mainloop ()
Top=tkinter. Tk ()
Top. Title (' dingzhaoyang ')
Top. Geometry (' 600 x300 ')
Ok=tkinter. Button (top, text='dzy', fg="blue", the command=ABC)
Ok. Place (x=250, y=130, width=50, height=20)

Top. Mainloop ()

CodePudding user response:

Didn't understand your problem,
Code has a problem, you provide child window can't use Tk () new, so try

ABC (def) :
Root=tkinter. Tk ()

Instead of

ABC (def) :
Root=tkinter.. Toplevel ()

CodePudding user response:

reference 1/f, old coconut response:
didn't understand your problem,
Code has a problem, you provide child window can't use Tk () new, so try

ABC (def) :
Root=tkinter. Tk ()

Instead of

ABC (def) :
Root=tkinter.. Toplevel ()

I change after the main window came out, the child window not come out after I click on the button

CodePudding user response:

Replication, a more

 
ABC (def) :
Root=tkinter. Toplevel ()

CodePudding user response:

The
reference old coconut reply: 3/f
copy, a more

nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related