关于列表条目和标签

时间:2018-10-25 18:29:53

标签: python list loops tkinter label

嗨,所以我有3个列表:tkinter窗口中的list1 list2和list3 我想这样做:

我希望用户在完成输入后每次按下“ enter”(输入),将标签T1更改为T2,并清除文本中的输入 当用户到达T5时,标签SUB1将更改为SUB2,而在用户达到T10之后,标签SUB2将更改为SUB3,对于list2中的每个值,还将显示list3中的1个值。谢谢,我希望我问很好地提出问题 这是我试图显示的代码,但是当我在条目上按Enter键时,甚至打印功能都无法正常工作:

import tkinter as tk 
from tkinter import ttk
import json 
from collections import defaultdict
import pickle

class Language(tk.Tk):
    def __init__(self, *args, **kwargs):

          tk.Tk.__init__(self, *args, **kwargs)
          frame = tk.Frame(self,)
          list1 = ["SUB1","SUB2","SUB3"]
          list2 = [['T1', 'T2', 'T3', 'T4'], ['T5', 'T6', 'T7', 'T8', 'T9'], 
                  ['T10', 'T11', 'T12', 'T13', 'T14', 'T15', 'T16', 'T17']]

          list3 = ['rocket', 'file', 'meth', 'pink', 'jelly', 'say', 'east',  'west']

          if i > len(list1):
              print("the end")
          else:
              for u in range(len(list1)):

                  label_sub = tk.Label(self, text=str(list1[i]) + ":",                                                      bg="green", )
                  label_sub.place(x=100, y=150)
              for b in range(len(list[u])):

                  def add(n):
                      n += 1
                      return n

                  if j > len(list2[b]):
                      i += 1 
                  else:
                      label_time = tk.Label(self, text=str(list2[b][add(j)]) +                                                      ":", bg="green", )
                      label_time.place(x=0, y=200)
                      label_word = tk.Label(self, text=str(list3[b]), 
                                                     bg="green", )
                      label_word.place(x=150, y=250)

                      q_entry = tk.Entry(self)
                      q_entry.bind('<Return>', print("something"))
                      q_entry.place(x=300, y=200)

root = Language() 
root.geometry("612x417") 
root.mainloop()

0 个答案:

没有答案