Apr-24-2020, 07:55 AM
Hey all,
I'm really stuck on a number of things here. I'm trying to make a page with many buttons for incrementing/decrementing settings that another script will use to run a machine. I am trying to do 3 things with these buttons:
increment/decrement the label (on this page)
increment/decrement the local value of each setting (in another file)
increment/decrement the sqlite database value
I'm sorry that it won't compile, that's just how stuck I am right now. I think the label change will work. I think the database change would work. I'm not really sure how to pass all these arguments to my increase/decrease functions, but I am trying 'partial' from what I read in other tutorials. But I really have no idea how to change a variable that is not in this file (and specifically how to change THAT variable, not work with the local copy made in the function). I was thinking of making the values in another file into a dictionary to easily be able to reference the other file variables. For now I put ??? in my function cuz I have no clue. Lastly, I have about 40 of these settings to make so I was also trying to make some function that will simplify writing all the code for these 40 buttons.
I'm really stuck on a number of things here. I'm trying to make a page with many buttons for incrementing/decrementing settings that another script will use to run a machine. I am trying to do 3 things with these buttons:
increment/decrement the label (on this page)
increment/decrement the local value of each setting (in another file)
increment/decrement the sqlite database value
I'm sorry that it won't compile, that's just how stuck I am right now. I think the label change will work. I think the database change would work. I'm not really sure how to pass all these arguments to my increase/decrease functions, but I am trying 'partial' from what I read in other tutorials. But I really have no idea how to change a variable that is not in this file (and specifically how to change THAT variable, not work with the local copy made in the function). I was thinking of making the values in another file into a dictionary to easily be able to reference the other file variables. For now I put ??? in my function cuz I have no clue. Lastly, I have about 40 of these settings to make so I was also trying to make some function that will simplify writing all the code for these 40 buttons.
from tkinter import * import machineProgram #the file where my settings variables live from functools import partial import sqlite3Connection def increase(setting_in_other_file, value, label, db_setting_name): value += 1 label['text'] = value setting_in_other_file = value sqlite3Connection.update_setting(conn, db_setting_name) def decrease(setting_in_other_file, value, label, db_setting_name): value -= 1 label['text'] = value setting_in_other_file = value sqlite3Connection.update_setting(db_setting_name) settingsPage = Tk() settingsPage.geometry("1024x600") settingsPage.columnconfigure([0, 1, 2, 3], minsize=5) sqlite3Connection.create_connection(db_file="somewhere on RPi") btn_decrease = Button(master=settingsPage, text="-", command=partial(increase, ???, machineProgram.machineClass.rinseTime, rinse_time_label, 'rinseTime'), width=10) btn_decrease.grid(row=2, column=0, sticky="nsew") rinse_time_label = Label(master=settingsPage, text=machineProgram.machineClass.rinseTime) rinse_time_label.grid(row=2, column=1) btn_increase = Button(master=settingsPage, text="+", command=partial(decrease, ???, machineProgram.machineClass.rinseTime, rinse_time_label, 'rinseTime'), width=10) btn_increase.grid(row=2, column=2, sticky="nsew") lbl_desc = Label(master=settingsPage, text="Rinse Time") lbl_desc.grid(row=2, column=3) settingsPage.mainloop()