鱼C论坛

 找回密码
 立即注册
查看: 2803|回复: 1

关于tkinter中label动态显示值的问题

[复制链接]
发表于 2020-4-2 20:19:12 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
想进一步优化孩子的拼音抽查小软件
但是标签l2中的显示文字text2不知道如何关联刷新
求大佬赐教,代码如下
  1. import tkinter as tk
  2. import random

  3. window = tk.Tk()
  4. window.title('拼音抽查系统')
  5. window.geometry('400x200')

  6. seq = ['a','o','e','i','u',
  7.         'ai','ei','ui','ao','ou','iu',
  8.        'ie','ue','er','an','en','in','un',
  9.        'ang','eng','ing','ong',
  10.         'b','p','m','f',
  11.         'd','t','n','l',
  12.         'g','k','h','j','q','x',
  13.         'zh','ch','sh','r','y','w']
  14. num = len(seq)
  15. index = 0

  16. text2 = tk.StringVar()
  17. on_hit1 = False
  18. on_hit2 = False

  19. def hit(a):
  20.     if a == False:
  21.         a = True
  22.         index = random.randint(0,num-1)
  23.         value = str(seq[index])
  24.         text2.set(value)
  25.     else:
  26.         a = False
  27.    
  28. l1 = tk.Label(window,text = '请读出下面的拼音',width = 100,height=2)
  29. l2 = tk.Label(window,textvariable = text2,font = ('Arial',18),bg = 'yellow',width = 100,height=2)   
  30. b1 = tk.Button(window,text = '下一个',width = 15,height = 2,command = hit(on_hit1))
  31. b2 = tk.Button(window,text = '退出',width = 15,height = 2,command = window.destroy)

  32. l1.pack()
  33. l2.pack()
  34. b1.pack()
  35. b2.pack()

  36. window.mainloop()
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2020-4-2 22:18:40 | 显示全部楼层
已经解决
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-4-30 23:14

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表