New to tkinter buttons not displaying?

Sorry if the title does not elucidate on the question - blame the way submissions work, I guess.

I'm new to tkinter, and I was given this code by a teacher to display how the module works. The module is installed on my machine, I checked 'help modules' to make sure.

import tkinter

class Application(tkinter.Frame):
   def _init_(self, master=None):
      tkinter.Frame._init_(self, master)
      self.pack()

      self.increase_button = tkinter.RADIOBUTTON(self)
      self.increase_button["text"] - "Increase"
      self.increase_button["command"] = self.increase_value
      self.increase_button.pack(side="right")

      self.increase_button - tkinter.RADIOBUTTON(self)
      self.increase_button["text"] = "Decrease"
      self.increase_button["command"] = self.decrease_value
      self.increase_button.pack(side="left")

   def increase_value(self):
      global mainval
      mainval *= 2
      print (mainval)
   def decrease_value(self):
      global mainval
      mainval /= 2
      print (mainval)

mainval = 1.0

root = tkinter.Tk()
app = Application(master=root)
app.mainloop()

So, it's supposed to display buttons that are made to increase and decrease a number that also displays on the screen.

When I test however, I just get a blank window, with no errors detected.

Upvotes: 0

Views: 102

Answers (1)

Alex Bohm
Alex Bohm

Reputation: 170

In Python the constructor for a class is named __init__ with two underscores on either side. You have one underscore on each side. Add the proper number of underscores to def _init_( and to tkinter.Frame._init_(

In tkinter the Radiobutton class only has one capital letter. Replace the tkinter.RADIOBUTTON( with tkinter.Radiobutton( The code should look something like this:

def __init__(self, master=None):
    tkinter.Frame.__init__(self, master)
    self.pack()

    self.increase_button = tkinter.Radiobutton(self)

Upvotes: 2

Related Questions