1

我正在尝试使用 RadioButton 制作一个基本的绘图程序来确定画笔的形状。

self.choseo = Radiobutton(text='Circle', variable=shape,indicatoron=0, value=1)
self.choser = Radiobutton(text='Rectangle', variable=shape,indicatoron=0, value=2)
self.chosea = Radiobutton(text='Arc', variable=shape,indicatoron=0, value=3)

对应于:

   if shape.get()==3:
      self.display.create_arc( self.x1, self.y1, self.x2,
          self.y2, fill = mycolor, outline= mycolor, tags = "line")
   elif shape.get()==2:
      self.display.create_rectangle( self.x1, self.y1, self.x2,
          self.y2, fill = mycolor, outline= mycolor, tags = "line")
   elif shape.get()==1:
      self.display.create_oval( self.x1, self.y1, self.x2,
          self.y2, fill = mycolor, outline= mycolor, tags = "line")

当我运行这个我得到这个错误:

"TypeError: get() takes exactly 1 argument (0 given)"

我如何使这项工作?

4

1 回答 1

4

你没有告诉它是什么shape,但你应该确保你使用IntVar.

试试下面的代码:

from Tkinter import *
master = Tk()
shape = IntVar() # ensure you use an instance of IntVar
Radiobutton(text='Circle', variable=shape, indicatoron=0, value=1, master=master).pack()
Radiobutton(text='Rectangle', variable=shape, indicatoron=0, value=2, master=master).pack()
Radiobutton(text='Arc', variable=shape, indicatoron=0, value=3, master=master).pack()

并将shape.get()按照您想要的方式工作。

于 2013-01-10T15:30:44.053 回答