Note that there are some explanatory texts on larger screens.

plurals
  1. POPython Execution Order with GUI
    primarykey
    data
    text
    <p>I'm having some issues with the following code. This is the first time that I'm working with a GUI and it's been a while since I've worked with python as well. When I try to execute the solfield function with the button, it yields no output.</p> <pre><code>from Tkinter import * import math master = Tk() n = float() I = float() def solfield(): pass label_coils = Label(text='Number of Coils Per Meter', textvariable=n) label_coils.grid() coils = Entry(master) coils.grid() label_current = Label(text='Current in Amps', textvariable=I) label_current.grid() current = Entry(master) current.grid() calculate_button = Button(text='Calculate', command=solfield()) calculate_button.grid() label_bfield = Label(text='B Field in +z Direction') label_bfield.grid() label_result = Label(text='solfield') label_result.grid() master.title('Coil Gun Simulation') master.mainloop() def solfield(): mu0 = math.pi*4e-7 solfield = mu0*n*I print solfield </code></pre> <p>Any other tips would be appreciated as well, as there will eventually be much more coding for me to do.</p> <p>This has been solved. If anyone is interested, here is the code after several fixes were made:</p> <pre><code>from Tkinter import * import math master = Tk() label_coils = Label(text='Number of Coils Per Meter') label_coils.grid() coils = Entry(master) coils.grid() label_current = Label(text='Current in Amps') label_current.grid() current = Entry(master) current.grid() def solfield(): mu0 = math.pi*4e-7 n = float(coils.get()) I = float(current.get()) fieldmag = mu0*n*I print fieldmag calculate_button = Button(text='Calculate', command=solfield) calculate_button.grid() label_bfield = Label(text='B Field in +z Direction') label_bfield.grid() label_result = Label(text='solfield') label_result.grid() master.title('Coil Gun Simulation') master.mainloop() </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload