0

I am doing one problem now. I want to print something by using "def select" in window 3. I need to give "def select" command to "proceed" button which is present in Window 2. I tried but I don't know how to do that.I am new to programming and developing GUI. So please help me to sort out this error.

class Win1(tk.Frame):
    def __init__(self, parent, controller):
        tk.Frame.__init__(self, parent)
        self.controller = controller
        Label(self, text= "ISMC", font= ('Helvetica 20 bold')).pack(padx=300, pady=5)
        B1=Button(self, text="AUTO", command=lambda:controller.show_frame(Win2)).pack(pady=20, padx=200)
        B2=Button(self, text="MANUAL", command=lambda:controller.show_frame(Win3)).pack(pady=20, padx=200)

class Win2(tk.Frame):
    def __init__(self, parent, controller):
        tk.Frame.__init__(self, parent)
        self.controller = controller
        Label(self, text= "ISMC", font= ('Helvetica 20 bold')).pack(padx=20, pady=40)
        Label(self, text= "Configurations", font= ('Helvetica 20 bold')).pack(padx=20, pady=40)

        v = StringVar(self, "1")

        values = {"BLOCK 1" : "1",
                  "BLOCK 2" : "2",
                  "BLOCK 3" : "3"}

        for (text, value) in values.items():
            Radiobutton(self, text = text, variable = v, bg="light blue", value = value,
                        indicator = 0, width = 10, command=self.do_auto).pack(pady=20)
     
        B1=Button(self, text="PROCEED", bg="green", fg="white", command=lambda :self.select(str2)).pack(pady=20)
        B2=Button(self, text="BACK", bg="red", fg="white", command=lambda:controller.show_frame(Win1)).pack(pady=20)

    def do_auto(self):
        for var in self.controller.frames[Win3].vars:
            var.set(1)
class Win3(tk.Frame):
    def __init__(self, parent, controller):
        tk.Frame.__init__(self, parent)
        self.array = []
        for i in range(no_of_relays):
             self.array.append("RELAY " + str(i+1))
        self.vars = []
        val_x=100
        val_y=10
        for i in range(len(self.array)):
            self.vars.append(StringVar())
            self.vars[-1].set(0)
            c = Checkbutton(self, text=self.array[i], variable=self.vars[-1], onvalue=1, offvalue=0,
                            command=lambda: self.printSelection(i)).place(x=val_x,y=val_y)                 
            if i<=30:
               val_x=val_x+0
               val_y=val_y+18
            if i>30<=60:
               val_x=200
               val_y=val_y+18
            if i==29:
               val_y=10
               val_x=200

 def printSelection(self, i):
         global str1
         global str2
         global str3
         str1=''
         str2=''
         str3=''
         data['id'] = self.array[i]
         last=data['id'].rsplit(' ', 1)[-1]
         data['Status'] = self.vars[i].get()
         str1=str1+last
         str3=str3+self.vars[i].get()
         selected_id.append(str1)
         selected_status.append(str3)
         str2="{'id':" + str(selected_id) + ",'Status':"  + str(selected_status)  + "}"
         
    def select(self,var):
        print(var)
        selected_status.clear()
        selected_id.clear()           
class Application(tk.Tk):
    def __init__(self, *args, **kwargs):
        tk.Tk.__init__(self, *args, **kwargs)
        window = tk.Frame(self)
        window.pack(side = "top", fill = "both", expand = True)
        self.frames = {}
        for F in (Win1, Win2, Win3):
            frame = F(window, self)
            self.frames[F] = frame
            frame.grid(row = 0, column=0, sticky="nsew")
        self.show_frame(Win1)
        
    def show_frame(self, window):
        frame = self.frames[window]
        frame.tkraise()
        self.title("Relay Test") 
        self.geometry('1500x1500')
        
app = Application()
app.mainloop()          

Can anyone please help me

  • It is more or less the same as your other [question](https://stackoverflow.com/questions/75432636/how-to-select-all-checkboxes-and-give-that-command-to-button-in-another-class-in), so the answer to that question applies to this one. – acw1668 Feb 14 '23 at 05:29

0 Answers0