from tkinter import *
# Create a window
spell_window = Tk()
# Give the window a title
spell_window.title('Spell Table')
table_Var = StringVar()
## table = ['T', 'a', 'b', 'l', 'e'] ## I think it needs to move through a list???
def spell_table():
s_table = monty_Var.get()
s_table += 'T' #Currently adds a 'T' each time the button is pressed
monty_Var.set(s_table)
the_label = Label(spell_window, width = 10, textvariable = table_Var,
font = ('Arial', 30), bg = 'red')
the_button = Button(spell_window, text = 'Next letter', command = spell_table)
the_label.pack(padx = 0, pady = 0)
the_button.pack(padx = 40, pady = 0)
だから基本的に私はラベルとボタンを作成し、次の文字ボタンを押してテーブルという単語を綴る必要があります。テーブルリスト内を移動してラベルに追加する方法がわからないだけです。
修正されたコードは次のとおりです。
from tkinter import *
spell_window = Tk()
spell_window.title('Spell Table')
table = ['T', 'a', 'b', 'l', 'e']
count = 1
def spell_table():
global count, table
the_label.config(text=table[:count])
if count < len(table):
count += 1
the_label = Label(spell_window, width = 10, text = "", font = ('Arial', 30), bg = 'red')
the_button = Button(spell_window, text = 'Next letter', command = spell_table)
the_label.pack(padx = 0, pady = 0)
the_button.pack(padx = 40, pady = 0)
spell_window.mainloop()
役に立たない変数を削除し、クリックするたびに増加する「count」変数を追加しました。はい、そのためのリストが必要でした。タプルも必要です。「the_label」のテキストをから変更しました
'textvariable = ' to 'text = ""'.
また、「カウント」に従ってリストをスライスしました。[:count] =カウントのインデックス値の前のすべて。また、ifステートメントは、変数が「テーブル」リストのインデックス値を超えた後、変数にさらにスペースを割り当てる必要がないため、効率を上げるためだけにあります。あなたも行方不明でした
spell_window.mainloop()
最後に。お役に立てれば!
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加