我仍然在研究这个相同的程序,我做了一点点进步。应用程序类型查找字典但所有信息都很不稳定。这是我到目前为止所得到的图片。
我是python的新手,也是编程新手。如果有人能帮助我解决我的代码的任何部分,我就会倾听并学习!到目前为止,这是我的代码。
from tkinter import *
from tkinter import ttk
#Experience Per Level Dictionary
import csv
exptable = csv.DictReader(open('C:/Users/LemDog/Desktop/WinPython 3.5.1.2/python-3.5.1.amd64/Scripts/Ragnarok Stuff/Ragnarok Base Level.csv'))
result = {}
for row in exptable: # should actually be called `row`
if row['Current Level'] not in result:
result[row['Current Level']] = row['Total EXP']
#All the math behind the GetKills Button
#Creates Tkinter Window
root = Tk()
root.title("How many Kills?")
mainframe = ttk.Frame(root, padding="3 3 70 12")
mainframe.grid(column=0, row=0, sticky=(N, W, E, S))
mainframe.columnconfigure(0, weight=1)
mainframe.rowconfigure(0, weight=1)
expper = StringVar()
currentlevel = StringVar()
desiredlevel = StringVar()
killamount = StringVar()
#OptionMenu From Dictionary
combobox = ttk.Combobox(mainframe)
combobox.grid(column=3, row=1)
combobox.set(result)
for item in [result]:
combobox.insert(END, result)
#Creats Current Level Text Entry Field
currentlevel = ttk.Entry(mainframe, width=10, textvariable=currentlevel)
currentlevel.grid(column=2, row=1, sticky=(W, E))
#Creates Exp Per Kill Text Entry Field
expper_entry = ttk.Entry(mainframe, width=10, textvariable=expper)
expper_entry.grid(column=2, row=2, sticky=(W, E))
#Creats Desired Level Text Entry Field
desiredlevel_entry = ttk.Entry(mainframe, width = 10, textvariable=desiredlevel)
desiredlevel_entry.grid(column=2, row=3, sticky=(W, E))
#Creates Button and Print Label for How Many Kills.
ttk.Label(mainframe, textvariable=killamount).grid(column=2, row=4, sticky=(W, E))
ttk.Button(mainframe, text="How many!?", command=getkills).grid(column=1, row=4, sticky=W)
ttk.Label(mainframe, text="Current Level").grid(column=1, row=1, sticky=W)
ttk.Label(mainframe, text="Experience Per Kill").grid(column=1, row=2, sticky=E)
ttk.Label(mainframe, text="Desired Level").grid(column=1, row=3, sticky=W)
for child in mainframe.winfo_children(): child.grid_configure(padx=5, pady=5)
root.mainloop()
任何帮助都表示赞赏!感谢您提前尝试!
答案 0 :(得分:0)
您似乎将__repr__
dict的整个result
设置为所选项目,而且您的数据似乎在列表中格式不正确。
尝试删除.set
和combobox.insert
for
循环,然后使用:
combobox.configure(values=list(result.values()))
# or result.keys() if that's your intent