|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
文件源码:
# -*- coding:utf-8 -*-
"""/ *----------------------------------------------------------------
文件名:main.py
文件功能描述: 这是一个可以帮你生成计算题目的程序
创建者: asky533
时间:2022.10.6
编译软件: Pycharm Professional 2022.1
---------------------------------------------------------------- * /
"""
from tkinter import *
import random
root = Tk()
OPTIONS = ["addition", "subtraction", "multiplication", "division"]
frame = Frame(root)
frame.pack(padx=10, pady=10)
v1 = StringVar()
v2 = StringVar()
v3 = StringVar()
variable = StringVar()
variable.set(OPTIONS[0])
def function_one(content):
if content.isdigit():
return True
else:
return False
testCMD = root.register(function_one)
a = Label(frame, text="Please Enter The total of the calculation questions:").grid(row=0, column=0)
b = Entry(frame, textvariable=v1, width=10, validate="key", validatecommand=(testCMD, "%P")).grid(row=0, column=1)
Label(frame, text="Please Choose your mode: Addition, subtraction, multiplication or division:").grid(row=1, column=0)
w = OptionMenu(root, variable, *OPTIONS)
w.pack()
def callback():
list = []
aides = 0
if w == OPTIONS[0]:
aides = "+"
elif w == OPTIONS[1]:
aides = "-"
elif w == OPTIONS[2]:
aides = "×"
elif w == OPTIONS[3]:
aides = "÷"
for x in range(a):
list.append(random.randrange(1, 100) + "." + random.randrange(1, 100) \
+ " " + aides + " " + random.randrange(1,100) + "." + random.randrange(1, 100)\
+ " ")
w1 = Message(root, text=list, width=100)
w1.pack()
Button(root, text="Submit", command=callback).pack()
mainloop()
报错信息:
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Users\asky5\AppData\Local\Programs\Python\Python310\lib\tkinter\__init__.py", line 1921, in __call__
return self.func(*args)
File "C:\Users\asky5\pythonProject\main.py", line 56, in callback
for x in range(a):
TypeError: 'NoneType' object cannot be interpreted as an integer
本帖最后由 hrpzcf 于 2022-10-23 02:16 编辑 import random
from tkinter import *
root = Tk()
OPTIONS = ["addition", "subtraction", "multiplication", "division"]
frame = Frame(root)
frame.pack(padx=10, pady=10)
v1 = StringVar()
v2 = StringVar()
v3 = StringVar()
variable = StringVar()
variable.set(OPTIONS[0])
def function_one(content):
if content.isdigit():
return True
else:
return False
testCMD = root.register(function_one)
a = Label(frame, text="Please Enter The total of the calculation questions:")
a.grid(row=0, column=0) # xxxxxxxxxxxx
b = Entry(
frame, textvariable=v1, width=10, validate="key", validatecommand=(testCMD, "%P")
)
b.grid(row=0, column=1) # xxxxxxxxxxxx
Label(
frame,
text="Please Choose your mode: Addition, subtraction, multiplication or division:",
).grid(row=1, column=0)
w = OptionMenu(root, variable, *OPTIONS)
w.pack()
def callback():
list = []
aides = "" # xxxxxxxxxxxx
v = variable.get()
if v == OPTIONS[0]: # xxxxxxxxxxxx
aides = "+"
elif v == OPTIONS[1]: # xxxxxxxxxxxx
aides = "-"
elif v == OPTIONS[2]: # xxxxxxxxxxxx
aides = "×"
elif v == OPTIONS[3]: # xxxxxxxxxxxx
aides = "÷"
for x in range(int(b.get())): # xxxxxxxxxxxx
list.append(
str(random.randrange(1, 100)) # xxxxxxxxxxxx
+ "."
+ str(random.randrange(1, 100)) # xxxxxxxxxxxx
+ " "
+ aides
+ " "
+ str(random.randrange(1, 100)) # xxxxxxxxxxxx
+ "."
+ str(random.randrange(1, 100)) # xxxxxxxxxxxx
+ " "
)
w1 = Message(root, text=list, width=100)
w1.pack()
Button(root, text="Submit", command=callback).pack()
mainloop()
|
评分
-
查看全部评分
|