|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
本帖最后由 yexing 于 2020-2-16 16:46 编辑
最近学完了 tkinter ,想着写一个随机抽数字的程序。
不料问题接踵而来,下面这个报错我找了半天愣是没找到报错原因。请问该如何解决?Traceback (most recent call last):
File "文件路径", line 58, in <module>
randoms.main()
File "文件路径", line 45, in main
Button(root, text="抽取", command=show)\
File "C:\Users\20688\AppData\Local\Programs\Python\Python38-32\lib\tkinter\__init__.py", line 2484, in grid_configure
self.tk.call(
_tkinter.TclError: bad option "-cloumn": must be -column, -columnspan, -in, -ipadx, -ipady, -padx, -pady, -row, -rowspan, or -sticky
源代码:from tkinter import *
import random as r
class Randoms:
def __init__(self):
self.start = 1
self.end = 100
def main(self):
root = Tk()
#显示被抽取到的数字
def show():
global var, one
one.delete(0, END)
var.set(self.get_random_num())
Label(root, textvariable=var, fg="red", font=("微软雅黑", 35), bg="yellow")\
.grid(row=3, column=0, columnspan=2, rowspan=2)
#布局设置
Label(root, text="开始数字:").grid(row=0, column=0)
Label(root, text="结束数字:").grid(row=1, column=0)
start = Entry(root)
end = Entry(root)
start.insert(0, "1")
end.insert(0, "100")
start.grid(row=0, column=1)
end.grid(row=1, column=1)
#设置开始和结束的数字
self.start = int(start.get())
self.end = int(end.get())
#初始化显示值
Label(root, text="被选中的数字是:").grid(row=2, column=0)
var = StringVar()
var.set("0")
one = Label(root, textvariable=var, fg="red", font=("微软雅黑", 35), bg="yellow")
one.grid(row=3, column=0, columnspan=2, rowspan=2)
#按钮组件
Button(root, text="抽取", command=show)\
.grid(row=4, cloumn=0)
Button(root, text="退出", command=root.quit)\
.grid(row=4, column=1)
mainloop()
def get_random_num(self):
return r.randint(self.start, self.end)
if __name__ == "__main__":
randoms = Randoms()
randoms.main()
如果还有其他问题,麻烦也指出来
提前感谢解决问题的大大
|
|