好的,我將以這個事實作爲前言,我是一個GTK 和 Python新手,但我一直無法挖掘出我需要的信息。基本上我所擁有的是單選按鈕列表,並且根據哪一個按鈕被選中,我需要將按鈕連接到不同的功能。我嘗試創建所有單選按鈕,然後創建一個令人厭惡的if/else塊來檢查每個按鈕上的sget_active()。問題是每一次都會有相同的按鈕返回true。有任何想法嗎?pyGTK單選按鈕幫助
下面是使用代碼:
#Radio Buttons Center
self.updatePostRadioVBox = gtk.VBox(False, 0)
self.updatePageRadio = gtk.RadioButton(None, "Updating Page")
self.updatePostRadio = gtk.RadioButton(self.updatePageRadio, "Updating Blog Post")
self.pageRadio = gtk.RadioButton(self.updatePageRadio, "New Page")
self.blogRadio = gtk.RadioButton(self.updatePageRadio, "New Blog Post")
self.addSpaceRadio = gtk.RadioButton(self.updatePageRadio, "Add New Space")
self.removePageRadio = gtk.RadioButton(self.updatePageRadio, "Remove Page")
self.removePostRadio = gtk.RadioButton(self.updatePageRadio, "Remove Blog Post")
self.removeSpaceRadio = gtk.RadioButton(self.updatePageRadio, "Remove Space")
#Now the buttons to direct us from here
self.returnMainMenuButton = gtk.Button(" Main Menu ")
self.returnMainMenuButton.connect("clicked", self.transToMain)
self.contentManageHBoxBottom.pack_start(self.returnMainMenuButton, False, False, 30)
self.contentProceedButton = gtk.Button(" Proceed ")
self.contentManageHBoxBottom.pack_end(self.contentProceedButton, False, False, 30)
if self.updatePageRadio.get_active():
self.contentProceedButton.connect("clicked", self.updatePage)
elif self.updatePostRadio.get_active():
self.contentProceedButton.connect("clicked", self.updatePost)
elif self.pageRadio.get_active():
self.contentProceedButton.connect("clicked", self.newPage)
elif self.blogRadio.get_active():
self.contentProceedButton.connect("clicked", self.newBlogPost)
elif self.addSpaceRadio.get_active():
self.contentProceedButton.connect("clicked", self.newSpace)
elif self.removePageRadio.get_active():
self.contentProceedButton.connect("clicked", self.removePage)
elif self.removePostRadio.get_active():
self.contentProceedButton.connect("clicked", self.removeBlogPost)
elif self.removeSpaceRadio.get_active():
self.contentProceedButton.connect("clicked", self.removeSpace)
你說得對。按鈕是要走的路。感謝您清除我的愚蠢,並在單選按鈕上的課程! – f4nt 2008-12-25 23:31:53