【发布时间】:2022-01-13 04:44:52
【问题描述】:
我正在尝试制作数字生成器,但遇到了问题。它不识别配置。我对 tkinter 有点陌生,并且凭借我对 python 的初学者知识,它真的让我头疼。这是代码:
from tkinter import messagebox
import random
from tkinter import *
from tkinter import ttk
window = Tk()
window.title("Random Number Generator")
window.geometry('350x200')
title_lbl = Label(window, text="Press the button to generate!").grid(row=0, column=1)
def rannum():
ran = random.randint(0, 10000000)
com = ans_lbl.configure(text=ran)
btn = Button(window, text='Randomize', command=rannum).grid(row=1, column=0)
ans_lbl = Label(window, text='').grid(row=2, column=0)
window.mainloop()
这是我收到的错误:
File "C:\Users\(redacted)\AppData\Local\Programs\Python\Python310\lib\tkinter\__init__.py", line 1921, in __call__
return self.func(*args)
File "c:\Users\(redacted)\Documents\(redacted)\(redacted)", line 15, in rannum
com = ans_lbl.configure(text=ran)
AttributeError: 'NoneType' object has no attribute 'configure'
【问题讨论】: