我一直在使用Tkinter GUI创建概率计算器。 我在数学方面比在python方面要好得多,所以请善待:)
我有一个Tkinter GUI,我可以选择一个用户。用户列表是从csv文件填充的。我已经创建了GUI,这样当我选择一个用户时,会立即从同一个csv文件中提取额外的信息。
我想要实现的是当我运行我的GUI时,填充名为inputTK
的{{1}}文件中的calculate
函数的结果被推送到inputTK
脚本并在tennisGameProbability
内的service_hold
字段中设置。
当我按下tennisGameProbability
按钮时,我想要在我的Tkinter GUI中显示Run
的结果。
当我跑"输入T"我一直收到以下错误:
tennisGameProbability
我该如何解决这个问题?
我的脚本
inputTk - >这是我的GUI脚本
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Python27\lib\lib-tk\Tkinter.py", line 1536, in __call__
return self.func(*args)
File "C:\Users\Magali\Desktop\Tennis\inputTK.py", line 85, in resultsgame
print tennisGameProbability.gameProb()
AttributeError: 'module' object has no attribute 'gameProb'
tennisGameProbability - >这个脚本运行我的概率计算 并且计算结果需要在我的GUI中显示
from Tkinter import *
import ttk
import csv
import tennisGameProbability
frame = Tk()
def calculate(*args):
try:
value_player1c = float(v1player1.get())/100
value_player1d = float(v2player1.get())/100
value_player1e = float(v3player1.get())/100
result_player_1.set((((value_player1c * value_player1d)-(value_player1c * value_player1e)) + value_player1e))
return ((((value_player1c * value_player1d)-(value_player1c * value_player1e)) + value_player1e))
except ValueError:
pass
def amount_of_sets():
return v6player1.get()
b1player1 = StringVar()
v1player1 = StringVar()
v2player1 = StringVar()
v3player1 = StringVar()
v6player1 = StringVar()
result_player_1 = StringVar()
result = StringVar()
aplayer1 = Label(frame, text="Player 1", font="{Bodoni MT} 10 bold").grid(row=8, column=1, columnspan=2, pady=15)
bplayer1 = Label(frame, text="Player Name").grid(row=9, column=1, sticky='w')
cplayer1 = Label(frame, text="1st Service Percentage:").grid(row=10, column=1, sticky='w')
ccplayer1 = Entry(frame, text="value", textvariable=v1player1, justify='center', width=10).grid(row=10, column=2)
dplayer1 = Label(frame, text="Points Won on 1st Serve: ").grid(row=11, column=1, sticky='w')
ddplayer1 = Entry(frame, text="value", textvariable=v2player1, justify='center', width=10).grid(row=11, column=2)
eplayer1 = Label(frame, text="Points Won on 2nd serve:").grid(row=12, column=1, sticky='w')
eeplayer1 = Entry(frame, text="value", textvariable=v3player1, justify='center', width=10).grid(row=12, column=2)
hplayer1 = Label(frame, text="Number of Sets:").grid(row=7, column=1)
hhplayer1 = Entry(frame, text="value", textvariable=v6player1, justify='center', width=10).grid(row=7, column=2)
myresult = Label(frame, textvariable=result, justify='center', width=10).grid(row=3, column=2)
f = open('testtennis.csv')
csv_f = csv.reader(f)
players_names = []
for row in csv_f:
players_names.append(row[0])
def newselection(event):
return player1()
box_value = StringVar()
box = ttk.Combobox(frame, textvariable=box_value, justify='center')
box.bind("<<ComboboxSelected>>", newselection)
box['values'] = players_names
box.current()
box.grid(column=2, row=9)
def player1():
with open("testtennis.csv") as fh:
for row in fh:
if (box_value.get()) in row:
player_name = row[0:row.find(',')]
row = row.replace(player_name+',', '')
firstservice = row[0:row.find(",")]
row = row.replace(firstservice+',', '')
points_firstserve = row[0:row.find(",")]
row = row.replace(points_firstserve+',', '')
points_secondserve = row[0:row.find(",")]
row.replace(points_secondserve+',', '')
v1player1.set(firstservice)
v2player1.set(points_firstserve)
v3player1.set(points_secondserve)
return box_value.get()
def oneclick():
return calculate()
def resultsgame():
print tennisGameProbability.gameProb()
run = ttk.Button(frame, text='Run', command=resultsgame)
run.grid(column=1, row=25, columnspan=4, ipadx=50, pady=25)
frame.geometry("1000x500+100+100")
mainloop()