单选按钮位于主菜单栏下方的子菜单中。
无法获取在PySide中单击的单选框的值,这在Tkinter中完美运行 以及如何在PySide中设置默认单选按钮?
在PySide中的:在pyside中更改/选择时无法获得单选框的值。这完美地在下面的tkinter
os.chdir(user+'database')
dbfiles=glob.glob('ias*.db')
#self.var=('ias'+yr+'.db') used to set default radio button? somehow
self.ag = QActionGroup(self)
for self.x in dbfiles: #dbfiles is a "list" of 3 databases
dbselect = self.ag.addAction(QAction(self.x, self, checkable=True))#how to set default?
self.menuDatabases.addAction(dbselect)
self.ag.triggered.connect(self.displaydb) #need to trigger something else?
def displaydb(self):
print(self.x) #need to print something else maybe?
在传统知识中;在这里完美地工作更改单选按钮并将数据库名称打印到文本框
os.chdir(os.path.expanduser('~')+'/Desktop/data/database')
self.dbfiles=glob.glob('ias*.db')
self.var=StringVar()
self.var.set('ias'+str(dte)+'.db')
for x in self.dbfiles:
dbfle.add_radiobutton(label=x,variable=self.var, value=x,command=self.sel)
def sel(self):
selection = "You changed to database: " + str(self.var.get())
self.b.delete(1.0,END)
self.b.insert(END,selection)
答案 0 :(得分:0)
设置开始时检查的操作之一:
self.ag.actions()[0].setChecked(true)
#selects first action, or do this at creation time
并更改回调:
def sel(self, action):
print action.text()