嗨,我是一个相对较新的开发人员(大约有一年的java经验,几周前才开始使用python),在python中让单选按钮在顶层窗口上工作遇到了困难。我在这里搜索了不同的问题和答案,并尝试了几个,但似乎没有一个有效。以下是相关代码:class MPTest(TestBed.Frame):
def __init__(self, master=NONE):
TestBed.Frame.__init__(self, master)
self.createWidgets()
def createWidgets(self):
ucThree = Button(root, text='Bids', font='Jokerman',
fg='white', bg='royal blue',
command=self.BidWindow)
ucThree.grid(row=2)
def BidWindow(self):
t = TestBed.Toplevel(self)
t.wm_title("Bid Info")
t.configure(background="navy")
v = IntVar()
v2 = IntVar()
bidtypelabel = Label(t, text='Bid Type: ', fg='white', bg='navy')
bidtypelabel.grid(row=0)
realtime = Radiobutton(t, text='Real Time', variable=v, value=1,
fg='white', bg='navy')
realtime.grid(row=1)
priority = Radiobutton(t, text='Priority', variable=v, value=2,
fg='white', bg='navy')
priority.grid(row=2)
listsearch = Radiobutton(t, text='List Search', variable=v, value=3,
fg='white', bg='navy')
listsearch.grid(row=3)
bidactionlabel = Label(t, text='Action: ', fg='white', bg='navy')
bidactionlabel.grid(row=0, column=1)
acceptbid = Radiobutton(t, text='Accept Bid', variable=v2, value=1,
fg='white', bg='navy')
acceptbid.grid(row=1, column=1)
rejectbid = Radiobutton(t, text='Reject Bid', variable=v2, value=2,
fg='white', bg='navy')
rejectbid.grid(row=2, column=1)
submit = Button(t, text='Submit', fg='white', bg='royal blue')
submit.grid(row=4, column=2)
root = TestBed.Tk()
root.configure(background="navy")
root.rowconfigure((0, 1, 2, 3, 4, 5, 6, 7, 8, 9), weight=1, pad=50)
root.columnconfigure(1, weight=1, pad=200)
app = MPTest(master=root)
app.mainloop()
我尝试过在IntVar()中设置变量同时等于0和1,然后在下一行设置一个集合。但是,这两种方法都不允许单选按钮selectable,并且将它们设置为1(已经分配的值)不会导致在打开窗口时选择第一个选项。我还尝试将变量的主变量设置为t(TopLevel)和TestBed。我所尝试的似乎都不管用。有时,将鼠标悬停在它们的上方会选择所有这些选项,这看起来有点小问题。然而,当我点击他们,他们不会保持选中无论我尝试基于我在这里和其他网站上找到的答案。我是Python新手,所以如果我做了一些明显愚蠢或错误的事情,我很抱歉,但任何帮助都将不胜感激。在