Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/python-2.7/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python TypeError:generator()正好接受2个参数(给定1个)_Python_Python 2.7 - Fatal编程技术网

Python TypeError:generator()正好接受2个参数(给定1个)

Python TypeError:generator()正好接受2个参数(给定1个),python,python-2.7,Python,Python 2.7,使用键盘快捷键时,不会显示错误,但如果使用鼠标事件,程序会抛出错误: TypeError: generator () takes exactly 2 arguments (1 given) 我希望这两项活动都能成功。在我看来,这适用于窗口.bind和按钮\u 003.bind(“,生成\u code.generator) 以下是代码: class Generator: def generator(self,event): if entry_01.get() == (&

使用键盘快捷键时,不会显示错误,但如果使用鼠标事件,程序会抛出错误:

TypeError: generator () takes exactly 2 arguments (1 given)
我希望这两项活动都能成功。在我看来,这适用于
窗口.bind
按钮\u 003.bind(“,生成\u code.generator)

以下是代码:

class Generator:
    def generator(self,event):

        if entry_01.get() == ("") or entry_szt1.get() == (""):

            tkMessageBox.showerror("Błąd", "Uzupełnij Numer reklamacji !")

        else:

            button_003 = Button(pageq,
                                text="Generuj kod",
                                font="none 20",
                                state=DISABLED
                                )
            button_003.place(x=1112, y=95)

            teraz = datetime.datetime.now()
            time = (teraz.strftime("%d.%m.%Y"))

            output = (time)
            output.split('.')
            dzien, miesiac, rok = output.split(".")
            rokk = rok
            mies = miesiac
            dzie = dzien
            my_list = list(rokk)
            one, two, three, four = my_list
            konc_roku = three + four
            k_roku = int(konc_roku)
            m = int(mies)
            tydzien = datetime.date(k_roku, m, 01).isocalendar()[1]
            data_biezaca = str(tydzien) + str(k_roku)
            nr_rekl = entry_01.get()

            nr_szt_w_rekl = entry_szt1.get()

            ean = barcode.get('code128', ('SVC^' + data_biezaca + '^' + nr_rekl + '^' + nr_szt_w_rekl))

            entry_03.insert(0, ean)
            # print(ean)

            ean.get_fullcode()
            filename = ean.save('code12')
            options = dict(compress=True,
                           module_height=6.0,  # 6.3
                           module_width=0.24,  # 0.28
                           text_distance=5.0,
                           font_size=7.0,
                           center_text=True,
                           quiet_zone=1.0)
            filename = ean.save('code12', options)

            """zamiana na pdf"""

            drawing = svg2rlg("code12.svgz")
            renderPDF.drawToFile(drawing, "file.pdf")  # zamiana na PDF
            # renderPM.drawToFile(drawing, "file.png", fmt="PNG") #zamiana na PNG

            os.startfile("file.pdf", "print")


Generowanie_kodu = Generator()

button_003 = Button(pageq,
                    text="Generuj kod",
                    font="none 20",
                    command=Generowanie_kodu.generator)
button_003.bind("<ButtonRelease-1>", Generowanie_kodu.generator)  
button_003.place(x=1112, y=95)

okno.bind("<Control_L><g>", Generowanie_kodu.generator)
类生成器:
def发生器(自身、事件):
如果条目_01.get()=(“”)或条目_szt1.get()=(“”):
tkMessageBox.batherror(“Błd”,“Uzupełnij Numer reklamacji!”)
其他:
按钮\u 003=按钮(第页,
text=“generauj kod”,
font=“无20”,
状态=禁用
)
按钮位置(x=1112,y=95)
teraz=datetime.datetime.now()
时间=(teraz.strftime(“%d.%m.%Y”))
输出=(时间)
output.split('.'))
dzien,miesiac,rok=输出.split(“.”)
韩国
mies=miesiac
哲=哲恩
我的列表=列表(rokk)
一,二,三,四=我的清单
konc_roku=三加四
k_roku=int(konc_roku)
m=int(mies)
tydzien=datetime.date(k_roku,m,01).isocalendar()[1]
数据_biezaca=str(tydzien)+str(k_roku)
nr_rekl=entry_01.get()
nr_szt_w_rekl=entry_szt1.get()
ean=barcode.get('code128',('SVC^'+data_biezaca+'^'+nr_rekl+'^'+nr_szt_w_rekl))
条目03.插入(0,ean)
#打印(ean)
ean.get_fullcode()
filename=ean.save('code12')
选项=dict(压缩=真,
模块高度=6.0,#6.3
模块宽度=0.24,#0.28
文本距离=5.0,
字体大小=7.0,
中心文本=真,
安静区=1.0)
filename=ean.save('code12',选项)
“”“zamiana na pdf”“”
图纸=svg2rlg(“代码12.svgz”)
renderPDF.drawToFile(图纸,“file.pdf”)35; zamiana na pdf
#renderrpm.drawToFile(绘图,“file.png”,fmt=“png”)35; zamiana na png
startfile(“file.pdf”,“print”)
Granowanie_kodu=发电机()
按钮\u 003=按钮(第页,
text=“generauj kod”,
font=“无20”,
命令=WANIE_kodu.generator)
按钮\u 003.bind(“,慷慨地使用\u kodu.generator)
按钮位置(x=1112,y=95)
okno.bind(“,Granowanie_kodu.generator)

我认为您的类中需要一个
\uuuu init\uuu
函数:

Class Generator:
    def __init__(self, event):
        self.event = event

然后您可以使用self.event作为event

我认为您需要在类中使用
\uuuu init\uuuu
函数:

Class Generator:
    def __init__(self, event):
        self.event = event
然后您可以将self.event用于event

您可以尝试以下方法:

类生成器:
def生成器(self,event=None):#您可以尝试以下方法:

类生成器:

def生成器(self,event=None):#现在我显示此错误:*TypeError:\uuuu init\uuuuuuuuuu()正好接受2个参数(给定1个)**您需要为事件提供一个值,我不确定它将如何工作现在我显示此错误:*TypeError:\uuu init\uuuuuuuuuuuuuuuuu()正好接受2个参数(给定1个)**您需要为事件提供一个值,我不知道如果不是这样的话,它将如何运作