请问怎么实现Radio的选中事件
请看我的代码,我想鼠标点击Radiobutton的时候,可以把选择的button通过回调的方式在selected的方法中打印出来? 现在回调时没有问题,但是我怎么知道那个是被选中的那?
还是Tk的时间模型不是这样的,应该用bind方法?但是我看doc里面Radiobutton没有bind的方法啊?还有问一下Tk里面不断的用TopLevel是为什么,我不太理解
代码如下:
#Driver examination
from Tkinter import *
class Question:
def __init__(self, title, answer, linearray):
"""Create new Question. linearray is question line array object. """
self.title = title
self.answer = answer
self.linearray = linearray
def isright(self, answer):
"""Inpute answer is right, 'A', 'B', 'C"""
return self.answer==answer
class QuestionPanel(Frame):
def __init__(self, master):
Frame.__init__(self, master)
self.top = master
# self.question = question
def validateAnswer(self, question):
""" Validate input answere is right"""
Label(self.top, text="You're right!!").grid(row=(question.linearray.__len__))
def selected(self, event=None):
print event
def randerQuestion(self, question):
"""Display spec quesiton on Window"""
# font = Font(size=12)
Label(self.top, text=question.title).pack(anchor=W)
count =1
v = IntVar()
for line in question.linearray:
Radiobutton(self.top, text=line, variable=v, value = line[0], command=self.selected).pack(anchor=W)
# count = count+1
question = Question("What's your age?","C",['A, 28','B, 29','C, 30'])
root = Tk()
#v = IntVar()
#for x in question.linearray:
# Radiobutton(root, text=x, variable = v, value=x[0]).pack(anchor=W)
questionPanel = QuestionPanel(root)
questionPanel.randerQuestion(question)
#QuestionPanel.validateAnswer(question)
#print "Size:", question.linearray.index
root.mainloop()
#for x in question.linearray:
# print x
#print 'Pls select one answer'
#print question.isright('A')
相关推荐
layui中使用jquery控制radio选中事件的示例代码
今天小编就为大家分享一篇layui中使用jquery控制radio选中事件的示例代码,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
VC单选按钮控件(Radio Button)用法
先为对话框加上2个radio button,分别是Radio1和Radio2。 问题1:如何让Radio1或者Radio2默认选上?如何知道哪个被选上了? 关键是选上,“默认”只要放在OnInitDialog()即可。三种方法可以让它选上, 第一种: ((CButton *)GetDlgItem(IDC_RADIO1))->SetCheck(TRUE);//选上 ((CBu
微信小程序之自定义Radio样式
wxml <radio-group bindchange="radioChange" class="radio-group-width"> <label class="radio-label" wx:if="{{rechargeValue.type=='关台'}}"> <view class="radio-text">余额</view> <radio value="1" ></radio> ...
radio change事件监听全攻略:从原理到实战,避开所有坑
在网页表单开发中,radio 单选按钮是高频使用的控件,而如何正确监听其选中状态变化,是许多前端初学者甚至老手都会踩坑的细节。与 click 事件不同,change 事件严格遵循“值发生变化才触发”的语义,因此在 radio 上它成为标准的事件监听方式。理解 name 分组带来的互斥与提交规则,是掌握监听逻辑的前提。绑定事件时,内联 onchange 虽然简单却不利于维护,addEventListener 适合静态表单,而事件委托则天然支持动态渲染的选项,是复杂页面的首选方案。基于事件对象、checked
jQuery实现radio第一次点击选中第二次点击取消功能
本篇文章主要介绍了jQuery实现radio第一次点击选中第二次点击取消功能的相关知识,具有很好的参考价值。下面跟着小编一起来看下吧


