嗨,我是一个相对较新的开发人员(大约是Java的1年,几周前才开始与Python合作(,并且很难在Python的Toplevel窗口上获得无线电按钮工作。我已经在这里搜索了不同的问题和答案,并尝试了其中几个,但似乎没有问题。这是相关的代码:
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的新手,所以很抱歉,如果我在做公然愚蠢或错误的事情,但任何帮助都将不胜感激。
问题是 fg='white'
参数collides带有无线电按钮的背景颜色(我看到白色,我认为这是您的情况相同的(。选择正在发生,只是在白色背景上画一个白点,所以您看不到它。
要补救,请在每个广播按钮中添加以下参数:
selectcolor='navy'
# or any colour of your preference that highlights the white dot
现在,您的广播按钮将具有相同的背景颜色,白色将脱颖而出。
参考线程