0

I am trying to make a program which could use a standard load by clicking the standload radiobutton or a variable load by clicking the variable load radiobutton. This variable load can be chosen by filling in a entry. Unfortunetely, I am not able to load the entry value directly into the value for the radiobutton. If I select the standard load it is working, but for the variable load I always obtain zero. Can someone show me what I am doing wrong? Thank you in advance!! The following code is what I have:

selectedload = tk.IntVar()

rad_standload = ttk.Radiobutton(tab1, text='Standard load (20 kN/m2)', value=pfloor,      variable=selectedload)
rad_standload.grid(row=17, column=1, sticky='W')

entry_int_frload = tk.IntVar()
entry_frload = ttk.Entry(master = tab1, textvariable = entry_int_frload)
entry_frload.grid(row=17, column=3, sticky='W')

rad_standloadfr = ttk.Radiobutton(tab1, text="Distributed load [kN/m2]:", value=entry_int_frload.get(),   variable=selectedload)
rad_standloadfr.grid(row=17, column=2, sticky="E")

I tried to create a function to put the .get() function in, but it is still not working. Hope that someone knows the answer.

JRiggles
  • 4,847
  • 1
  • 12
  • 27
  • 1
    This isn't very clear. You mentioned that you attempted to resolve this with a function, but there isn't a function in your example. It's better to provide a [minimal reproducible example](https://stackoverflow.com/help/minimal-reproducible-example) so that we can copy and paste your failed attempt. It's likely that you are calling the `get` method too soon before a value is bound to your `IntVar`. – Rory Jun 20 '23 at 14:55
  • https://ibb.co/xXzyL93. The grid isn't correct layout. the correct is rad_standload.grid(row=0, column=1, sticky='W') entry_frload.grid(row=0, column=3, sticky='W') rad_standloadfr.grid(row=0, column=2, sticky="E"). But what is pfloor is? – toyota Supra Jun 21 '23 at 11:30
  • You will have to write two functions Standard_load and Distributed_load. – toyota Supra Jun 21 '23 at 11:35
  • What is value of m2? – toyota Supra Jun 21 '23 at 12:09

1 Answers1

0

You can trace the tkinter variable entry_int_frload and update the value option of rad_standloadfr:

def update_rad_standloadfr(*args):
    try:
        # change the value option of rad_standloadfr
        rad_standloadfr.config(value=entry_int_frload.get())
    except tk.TclError as ex:
        print(ex)

# call update_rad_standloadfr() whenever entry_int_frload is changed
entry_int_frload.trace_add("write", update_rad_standloadfr)

Note that rad_standloadfr will be deselected if it is currently selected after changing its value option.

acw1668
  • 40,144
  • 5
  • 22
  • 34