如何将.get()函数与单选按钮一起使用

2024-10-01 13:29:59 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图用一个单选按钮制作一个基本的绘图程序来确定画笔的形状。在

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)

对应于:

^{pr2}$

当我运行这个时,我得到了这个错误:

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

我该怎么做?在


Tags: textself程序绘图valuevariable按钮形状
1条回答
网友
1楼 · 发布于 2024-10-01 13:29:59

您没有告诉您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()将以您想要的方式工作。在

相关问题 更多 >