Commit c2092ddd by BellCodeEditor

auto save

parent d342feb7
Showing with 22 additions and 2 deletions
...@@ -27,9 +27,20 @@ class Note(): # 便签、笔记 ...@@ -27,9 +27,20 @@ class Note(): # 便签、笔记
self.but.place(x=240, y=305) self.but.place(x=240, y=305)
# 展示所有的文字 # 展示所有的文字
self.y = 20 self.y = 20
self.val = 0 # 单选框的value参数
self.v = IntVar() # 设置关联变量
for info in alist: for info in alist:
self.canvas.create_text(40, self.y, text=info, self.canvas.create_text(40, self.y, text=info,
font=("宋体", 11), anchor=W, fill='#FF9900') font=("宋体", 11), anchor=W, fill='#FF9900')
#渲染代办事项的同时,将单选框组件也渲染
self.select = tkinter.Radiobutton(self.canvas,image=self.box,
value=self.val,variable=self.v,width=25, height=15,
borderwidth=0)
#第一个参数:画布对象,二:加载方框图片
self.select.place(x=-20,y=self.y-10)
#代码在for循坏里,每次在用过Radiobutton()方法后,让value对应的参数值增加1
#这样才能让每一个单选框组件设置一个不同的编号
self.val += 1
self.y += 30 self.y += 30
def get_info(self): def get_info(self):
...@@ -39,6 +50,11 @@ class Note(): # 便签、笔记 ...@@ -39,6 +50,11 @@ class Note(): # 便签、笔记
alist.append(info) alist.append(info)
self.canvas.create_text(40,self.y,text=info,font=("宋体",11), self.canvas.create_text(40,self.y,text=info,font=("宋体",11),
anchor=W, fill='#FF9900') anchor=W, fill='#FF9900')
self.select = tkinter.Radiobutton(self.canvas,image=self.box,
value=self.val,variable=self.v,width=25, height=15,
borderwidth=0)
self.select.place(x=-20,y=self.y-10)
self.val += 1
self.y += 30 self.y += 30
......
...@@ -6,10 +6,14 @@ canvas = tkinter.Canvas(root, width=300, height=340, bg="lightblue") ...@@ -6,10 +6,14 @@ canvas = tkinter.Canvas(root, width=300, height=340, bg="lightblue")
canvas.place(x=0, y=0) canvas.place(x=0, y=0)
# ++++++++++++++++++++++++++++++++++++++++++++++++++++ # ++++++++++++++++++++++++++++++++++++++++++++++++++++
def func(): def func():
num = v.get() num = v.get() #获取选择的内容
print("你选择了:",num) print("你选择了:",num)
v = tkinter.IntVar() v = tkinter.IntVar()
#用radiobutton创建了四个单选组件
#value相当于给每个组件设置一个编号
#variable是tkinter.IntVar()生成的一个整数变量,
#四个都设一样,相当于关联在一起,这样四个选项只能选一个
rb1 = tkinter.Radiobutton(root,text='体育',value=1,variable=v,command=func) rb1 = tkinter.Radiobutton(root,text='体育',value=1,variable=v,command=func)
rb2 = tkinter.Radiobutton(root,text='美术',value=2,variable=v,command=func) rb2 = tkinter.Radiobutton(root,text='美术',value=2,variable=v,command=func)
rb3 = tkinter.Radiobutton(root,text='音乐',value=3,variable=v,command=func) rb3 = tkinter.Radiobutton(root,text='音乐',value=3,variable=v,command=func)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment