如何在python中修复tkinter问题?

2024-10-03 15:22:38 发布

您现在位置:Python中文网/ 问答频道 /正文

我需要帮助找出为什么这不起作用,我正试图通过tkinter的图形用户界面编程一个掷骰子的应用程序

这是一个骰子滚动应用程序,有输入/输出通过tkinter

from tkinter import *
import random
import time

rolls = 1
master = Tk()
logo = PhotoImage(file="dice.gif")
Label(master, image=logo).grid(row=0)
Label(master, text="How many dice do you have?").grid(row=1)
Label(master, text="How many sides do you have?").grid(row=2)
dicenum_entry = int(dicenum.get())
dicenum_entry.grid(row=1, column=1)
sidenum_entry = int(sidenum.get())
sidenum_entry.grid(row=2, column=1)
Button(master, text='Enter', command=master.destroy).grid(row=3, column=1, sticky=W, pady=4)
mainloop()

min = 1

def dice_result():
    random.randint(min, sidenum_entry)

def dice_roll():
    master= Tk()
    count = 0
    while count < dicenum_entry:
        count = count + 1
        Label(master, text="Rolling the dice(s)...").grid(row=0)
        time.sleep(2)
        Label(master, text="The values are...").grid(row=1)
        Label(master, command=dice_result).grid(row=2)
        mainloop()

def question():
    master = Tk()
    Label(master, text="Do you want to roll the dice?").grid(row=0)
    yes = Button(master, text="Yes", command=dice_roll).grid(row=1)
    no = Button(master, text="No", command=master.destroy).grid(row=2)
    mainloop()

question()

运行时出现以下错误:

回溯(最近一次呼叫): 文件“H:\Computing\Tony\Dice Roller\Dice\u roller2.py”,第11行,in dicenum\u entry=int(dicenum.get()) NameError:未定义名称“dicenum”


Tags: textimportmasteryoutkintercountdicelabel