djdjoosusu 发表于 2020-4-2 20:19:12

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

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

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

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

text2 = tk.StringVar()
on_hit1 = False
on_hit2 = False

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

l1.pack()
l2.pack()
b1.pack()
b2.pack()

window.mainloop()

djdjoosusu 发表于 2020-4-2 22:18:40

已经解决
页: [1]
查看完整版本: 关于tkinter中label动态显示值的问题