Hello. For my application, I have created an optionsmenu and I select some values there. The next time I open that menu, I want to be able to see the latest values that have been set:
I make a canvas within canvas when I click the "Settings" button. Within the settings, I wan to change some values and save them so the next time I open the settings I can see what is the current configuration:
https://ibb.co/X7Kcw5B
When I select the values, and confirm, I save them into a new variable self.options_new. Now the next time I open the settings I want to see that value instead of a default "One" "Two' and etc.
HOw can I do that?
Code:
def settings_gui(self):
self.innercanvas = tk.Canvas(canvas, width=500, height=500)
self.options1 = tk.StringVar(self.innercanvas)
self.options1.set("First") # WANT TO SHOW THE LAST UPDATED VALUE BUT IT DOES NOT EXIST AT THIS POINT
self.options2 = tk.StringVar(self.innercanvas)
self.options2.set("TWO") # default value
self.options3 = tk.StringVar(self.innercanvas)
self.options3.set("Three") # default valueC
self.options4 = tk.StringVar(self.innercanvas)
self.options4.set("fOUR") # default value
self.options5 = tk.StringVar(self.innercanvas)
self.options5.set("fIVE") # default value
w1 = tk.OptionMenu(self.innercanvas, self.options1, "one", "two", "three")
w2 = tk.OptionMenu(self.innercanvas, self.options2, "one", "two", "three")
w3 = tk.OptionMenu(self.innercanvas, self.options3, "one", "two", "three")
w4 = tk.OptionMenu(self.innercanvas, self.options4, "one", "two", "three")
w5 = tk.OptionMenu(self.innercanvas, self.options5, "one", "two", "three")
self.canvas_inner_window=canvas.create_window(50, 25, anchor='nw', window=self.innercanvas)
confirm_button = tk.Button(self.innercanvas, text="Confirm",font='Helvetica 12 bold', width=20, height=2, command = self.ok)
self.innercanvas.create_window(250,400,window = confirm_button)
self.innercanvas.create_window(50,250,window = w1)
self.innercanvas.create_window(150,250,window = w2)
self.innercanvas.create_window(250,250,window = w3)
self.innercanvas.create_window(350,250,window = w4)
self.innercanvas.create_window(450,250,window = w5)
def ok(self):
print ("value is:" + self.options1.get())
self.options1_new = self.options1
print ("value is:" + self.options2.get())
self.options2_new = self.options2
print ("value is:" + self.options3.get())
self.options3_new = self.options3
print ("value is:" + self.options4.get())
self.options4_new = self.options4
print ("value is:" + self.options5.get())
self.options5_new = self.options5
self.innercanvas.delete("all")
canvas.delete(self.canvas_inner_window)
https://ibb.co/X7Kcw5B
When I select the values, and confirm, I save them into a new variable self.options_new. Now the next time I open the settings I want to see that value instead of a default "One" "Two' and etc.
HOw can I do that?