IntVar()を使用しても、ラベル内の変数を更新できません。私はおそらく慢性的に何かをやっている。変数を変更してラベルを更新するNimゲームを作成しようとしました。Python 3 Tkinterラベルを更新/更新するには? Nim Game
# ministry of trade
from tkinter import *
import random
# create root window
root = Tk()
# ministry of variables
lst_choice = [1,2]
lst_player = [1,2]
player=random.choice(lst_player) #set random player
playervar = StringVar()
playervar.set(player)
# Set the initial state
state=7 # number of objects
statevar = IntVar()
statevar.set(state)
winner=0
winnervar = IntVar()
winnervar.set(winner)
move=0
movevar = IntVar()
movevar.set(move)
def move1():
# move is assigned
global statevar
global playervar
global winnervar
if statevar.get()>0:
statevar.set(statevar.get() - 1)
print(statevar.get()) #for testing only
return statevar
if statevar.get()==0: # check win status - win, lose, stalemate
winnervar.set(playervar.get())
print(winnervar.get()) #for testing only
return winnervar
if playervar.get()==1: # switch players 2->1, 1->2 go back to the valid move line
playervar.set(2)
print(playervar.get()) #for testing only
return playervar
else:
playervar.set(1)
print(playervar.get()) #for testing only
return playervar
root.update_idletasks()
def move2():
return
# Holy Roman Empire of the Widget Nation
# electorate of Label
labelAantalMunten = Label(root, text=("Aantal munten op stapel ",statevar.get())) #state
labelAantalMunten.pack() # orders to add the widget label to the root window and display it
labelWelkSpeler = Label(root, text=("Nu is speler ",playervar.get()," aan de beurt")) #player
labelWelkSpeler.pack()
labelWelkWinaar = Label(root, text=("Speler ",winnervar.get()," heeft gewonnen!")) #winner
labelWelkWinaar.pack()
# electorate of Button
button1 = Button(root, text="neem 1 steen", command=move1)
button1.pack()
button2 = Button(root, text="neem 2 stenen", command=move2)
button2.pack()
# start the main events loop
root.mainloop()
"できない" とは何を意味するのでしょうか?なぜあなたはできないのですか?エラーが出ていますか?プログラムはクラッシュしますか? –