0

I can get the GUI to display by changing the button command with ,self but the button still wont work. Any suggestion? The main issue is def btnclick() and btn1 command=BtnClick() The rest button does not function either but it can open and display. I was thinking it was an indent error but I tried a few differences without seeing a direct change. I have also tried moving the def classes above and below other lines of code

class MainWindow(Frame):
    def __init__(self):
        Frame.__init__(self)
        self.master.minsize(350,150)
        self.grid(sticky=E+W+S+N)

        self.save_dir = None #learn more about this: Try being more spasatious , ecfic
        self.filename_open = None #learn more about this

        top = self.winfo_toplevel()
        top.rowconfigure(0, weight=1)
        top.columnconfigure(0, weight=1)

        rd1 = random.randint(1, 20)
        rd2 = random.randint(1, 20)
        aiR1 = 20 - rd1
        aiR2 = 20 - rd2
        totalDif1 = 20 - rd1 - rd2
        totalDif2 = 20 - rd1 + rd2

        #---------Labels&Names---------#
        myLabel = Label(self, text = "tt")
        myLabel.grid(row=3, column=0, pady=2, padx=2, sticky=E+W+N+S)
        lbl1 = Label(self, text="My Roll", bg="#FFE19E")
        lbl1.grid(row=3, column=1, pady=2, padx=2, sticky=E+W+N+S)
        lbl2 = Label(self, text = "Ai Roll", bg="#FFE19E")
        lbl2.grid(row=3, column=2, pady=2, padx=2, sticky=E+W+N+S)
        lbl3 = Label(self, text = "Second Roll", bg="#FFE19E")
        lbl3.grid(row=5, column=1, pady=2, padx=2, sticky=E+W+N+S)
        lbl4 = Label(self, text = "Ai ReRoll", bg="#FFE19E")
        lbl4.grid(row=5, column=2, pady=2, padx=2, sticky=E+W+N+S)

        roll1 = Label(self, text=rd1)
        roll1.grid(row=4, column=1, pady=2, padx=2, sticky=E+W+N+S)
        roll2 = Label(self, text=aiR1)
        roll2.grid(row=4, column=2, pady=2, padx=2, sticky=E+W+N+S)
        roll3 = Label(self, text=rd2)
        roll3.grid(row=6, column=1, pady=2, padx=2, sticky=E+W+N+S)
        roll4 = Label(self, text=aiR2)
        roll4.grid(row=6, column=2, pady=2, padx=2, sticky=E+W+N+S)

        #---------Buttons---------#
        btn1 = Button(self, text="Roll", command=BtnClick(), activeforeground="red", relief="raised")
        btn1.grid(row=0, column=0, pady=2, padx=2, sticky=E+W+N+S)

        btn2 = Button(self, text="grey", command=BtnReset(),relief="raised")
        btn2.grid(row=1, column=0, pady=2, padx=2, sticky=E+W+N+S)

    def BtnClick():
        myLabel = Label(self, text = " ")
    def BtnReset():
        myLabel = Label(self, text = " ")

if __name__ =="__main__":
    d = MainWindow()
    d.mainloop()
  • The root cause is the same as the question this is a duplicate of. You have a further problem in that you create a `Label` in your functions but then you don't call `grid` so they will be invisible. – Bryan Oakley Dec 08 '20 at 17:26
  • Besides other great comments, one other problem is that when you send the keyword argument ```command=BtnClick()```, you actually are calling the ```BtnClick``` here during definition. What you need to do is just to write ```command=BtnClick``` without the ```()```. – Vince Payandeh Dec 08 '20 at 17:28
  • Also you have to let the button callbacks have `self` as argument: `def BtnClick(self)` anu when you call it you need to call the instance method: `command=self.BtnClick` – figbeam Dec 08 '20 at 17:30
  • Thank you for the assistance. – Christopher Osborne Dec 08 '20 at 18:46
  • I noticed that it was an issue with the self/() call , but I wasn't sure of the format as this is the first time I've tried developing something without direct instruction. Feels a bummer not spending the extra hours staring at it. Thanks again for the help you three! – Christopher Osborne Dec 08 '20 at 18:47

0 Answers0