Python Forum
[Tkinter] button, how to do many things
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tkinter] button, how to do many things
#4
My first example would be something you could add to your machine class. My last example is something that would be used only if you couldn't modify the machine class. Since it is short you could include it (only the MachineParameter class) in you GUI file. I would write a function that created an instance of the class, created a label, an increment and a decrement button. Something kind of like this:
def new_machine_control(title, param_name, db_field_name, row):
    title_lbl = Label(master=settingsPage, 'text'=title)
    title_lbl.grid('row' = row, 'column' = 0)
    value_lbl = Label(master=settingsPage)
    value_lbl.grid('row' = row, 'column' = 3)
    param = MachineParameter(machineProgram.machineClass, param_name, 1, value_lbl, \
                             sqlite3Connection, db_field_name)
    param.incr(0)
    incr_btn = Button(master=settingsPage, text="+", command=partial(param.incr))
    incr_btn.grid('row' = row, 'column' = 1)
    decr_btn = Button(master=settingsPage, text="-", command=partial(param.decr))
    incr_btn.grid('row' = row, 'column' = 2)
    return param

new_machine_control('Rinse TIme', 'rinseTime', db_stuff, 1)
new_machine_control('Tumble TIme', 'tumbleTime', db_stuff, 2)
That would make a fairly compact GUI file even if you have many parameters to control.

Be aware I have no idea how the database connection stuff would look. I haven't made it to using databases in python (yet). You might also want to save the buttons and the title in the MachineParameter class so everything would be in one place. I hate throwing things away and not being able to get to them again
Reply


Messages In This Thread
button, how to do many things - by nanok66 - Apr-24-2020, 07:55 AM
RE: button, how to do many things - by deanhystad - Apr-24-2020, 04:59 PM
RE: button, how to do many things - by nanok66 - Apr-25-2020, 03:21 AM
RE: button, how to do many things - by deanhystad - Apr-25-2020, 03:57 AM
RE: button, how to do many things - by nanok66 - Apr-25-2020, 09:53 PM
RE: button, how to do many things - by deanhystad - Apr-25-2020, 10:34 PM
RE: button, how to do many things - by nanok66 - Apr-25-2020, 10:53 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  [PySimpleGui] How to alter mouse click button of a standard submit button? skyerosebud 3 5,195 Jul-21-2019, 06:02 PM
Last Post: FullOfHelp

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020