TypeError:set()只需要2个参数(给定1个)

时间:2015-03-22 01:14:22

标签: python tkinter

我在Python 2.7中创建了这个程序:

import Tkinter
import os

root = Tkinter.Tk()
root.wm_title("Select an Item")
root.deiconify()

itemoptionwindow = Tkinter.Tk()
itemoptionwindow.wm_title("Select an Option")
itemoptionwindow.withdraw()

itemslist = []
itemsdir = "C:/Users/Miller/Documents/items/"

itemoption1 = False
itemoption2 = False
itemoption3 = False
itemprice = Tkinter.IntVar()
itemprice.set()

for file in os.listdir(itemsdir):
    if file.endswith(".txt"):
        itemslist = open(os.path.join(itemsdir + file), "r")

for file in os.listdir(itemsdir):
    if file.endswith(".txt"):
        itemslist2 = open(os.path.join(itemsdir + file), "r")

def addtoorder(itemnum):
    print "hi"
    print itemnum
    item = []
    print "bye"
    line = itemslist2.read().split()
    print line[0]
    print "my"
    global itemprice
    if line[0] == itemnum:
        print "herro"
        item.append(line[8])
        itemprice.set(itemprice.get() + float(line[4]))
        print itemoption3
        if itemoption1 == True:
            item.append(line[1])
            itemprice.set(itemprice.get() + float(line[5]))
        if itemoption2 == True:
            item.append(line[2])
            itemprice.set(itemprice.get() + float(line[6]))
        if itemoption3 == True:
            item.append(line[3])
            itemprice.set(itemprice.get() + float(line[7]))
        print item
        print itemprice.get()
        root.deiconify()
        itemoptionwindow.withdraw()
        root.update_idletasks()
        print "done"

def rootupdate():
    root.update()
    print itemprice.get()
    print "hi"

menuitem1 = Tkinter.Button(root, text = "Chicken Nuggets", command = lambda: createitemwindow(itemnum="0"))
menuitem1.pack()
pricelabel = Tkinter.Label(root, itemprice)
pricelabel.pack()
updatebut = Tkinter.Button(root, text = "update window", command = rootupdate())
updatebut.pack()
buybutton = Tkinter.Button(root, text = "BUY")
buybutton.pack()

def switchio1():
    global itemoption1
    if itemoption1 == False:
        itemoption1 = True
    elif itemoption1 == True:
        itemoption1 = False

def switchio2():
    global itemoption2
    if itemoption2 == False:
        itemoption2 = True
    elif itemoption2 == True:
        itemoption2 = False

def switchio3():
    global itemoption3
    if itemoption3 == False:
        itemoption3 = True
        print itemoption3
    elif itemoption3 == True:
        itemoption3 = False
        print itemoption3

def createitemwindow(itemnum):
    row = itemslist.read().split()
    if row[0] == itemnum:
        itemoptionwindow.deiconify()
        root.withdraw()
        option1 = Tkinter.Button(itemoptionwindow, text = row[1], command = switchio1)
        option1.pack()
        option2 = Tkinter.Button(itemoptionwindow, text = row[2], command = switchio2)
        option2.pack()
        option3 = Tkinter.Button(itemoptionwindow, text = row[3], command = switchio3)
        option3.pack()
        addtoorderbut = Tkinter.Button(itemoptionwindow, text = "Add Item To Order", command = lambda: addtoorder(itemnum))
        addtoorderbut.pack()

Tkinter.mainloop()

但是,当我运行它时,我收到此错误:

Traceback (most recent call last):
    File "DigitalDiningSoftware.py", line 19, in <module>
        itemprice.set()
TypeError: set() takes exactly 2 arguments (1 given)

我在互联网上搜索过,但似乎没有其他人遇到过这个问题,我觉得这个问题很明显。有谁知道问题是什么?

0 个答案:

没有答案