#1
  1. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Posts
    67
    Rep Power
    11

    Problem with variables and Tkinter...


    OK, so I'v got 11 radio buttons hooked up to one variable: self.weaponbonus. However, no matter what radio button I have checked, self.weaponbonus is treated as 0. This is my code:
    Code:
            self.weaponbonus = IntVar
    
            self.radio1 = Radiobutton(master, text="+1", variable=self.weaponbonus, value=1)
            self.radio1.grid(row=1, column=0)
            self.radio2 = Radiobutton(master, text="+2", variable=self.weaponbonus, value=2)
            self.radio2.grid(row=1, column=1)
            self.radio3 = Radiobutton(master, text="+3", variable=self.weaponbonus, value=3)
            self.radio3.grid(row=1, column=2)
            self.radio4 = Radiobutton(master, text="+4", variable=self.weaponbonus, value=4)
            self.radio4.grid(row=1, column=3)
            self.radio5 = Radiobutton(master, text="+5", variable=self.weaponbonus, value=5)
            self.radio5.grid(row=1, column=4)
            self.radio6 = Radiobutton(master, text="+6", variable=self.weaponbonus, value=6)
            self.radio6.grid(row=2, column=0)
            self.radio7 = Radiobutton(master, text="+7", variable=self.weaponbonus, value=7)
            self.radio7.grid(row=2, column=1)
            self.radio8 = Radiobutton(master, text="+8", variable=self.weaponbonus, value=8)
            self.radio8.grid(row=2, column=2)
            self.radio9 = Radiobutton(master, text="+9", variable=self.weaponbonus, value=9)
            self.radio9.grid(row=2, column=3)
            self.radio10 = Radiobutton(master, text="+10", variable=self.weaponbonus, value=10)
            self.radio10.grid(row=2, column=4)
            self.radioran = Radiobutton(master, text="Random", variable=self.weaponbonus, value=99)
            self.radioran.grid(row=3, column=0, columnspan=5)
    
            totalweaponbonus = self.weaponbonus 
            if totalweaponbonus == 99:
                totalweaponbonus = random.randint(1, 10)
    Does anyone know what's wrong?
    Thanks.
    Before you criticize someone, walk a mile in their shoes, that way when you do criticize them, you're a mile away and you have their shoes!
  2. #2
  3. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Posts
    67
    Rep Power
    11
    Anyone? I really need help!
  4. #3
  5. Hello World :)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2003
    Location
    Hull, UK
    Posts
    2,537
    Rep Power
    69
    Hey Baltor,

    I'm not a GUI guy persay but i did mess around with it for an hour of so last night, no luck. By "self.weaponbonus is treated as 0" do you mean you got the value PYV0 or something similar (which is what i was getting), it appears to me that the RadioButton widget just isn't updating the value correctly? But i wouldn't know howe to fix this.. I was looking at the online docs on Radiobutton but there examples were very similar to yours (and didn't work either)

    Sorry,

    Mark.
    programming language development: www.netytan.com Hula

  6. #4
  7. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Posts
    67
    Rep Power
    11
    Yeah, I get PYVO.
    Also, if I have:
    Code:
    self.weaponbonus = int()
    Instead of:
    Code:
    self.weaponbonus = IntVar
    I get self.weaponbonus = 0. I'm really confused; I don't see any reason why this wouldn't work.
    Before you criticize someone, walk a mile in their shoes, that way when you do criticize them, you're a mile away and you have their shoes!
  8. #5
  9. Hello World :)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2003
    Location
    Hull, UK
    Posts
    2,537
    Rep Power
    69
    i've tried int() aswell, it should work as far as i can see! Maybe were just missing somthing but.. and like i said i'm not really into the whole GUI thing! I've always opted for the web based taskes instead of GUI's, but give it a few years and i dout you'll be able to see much of a border between the too, at least program wise.

    Sorry Baltor, maybe this i question that should be asked to the powers that be on comp.lang.python:

    http://www.dbforums.com/f97/

    Mark.
    programming language development: www.netytan.com Hula

  10. #6
  11. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Posts
    67
    Rep Power
    11
    OK, thanks for your help.
    I've posted it there.

IMN logo majestic logo threadwatch logo seochat tools logo