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

2024-05-20 13:42:40 发布

您现在位置:Python中文网/ 问答频道 /正文

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

TypeError: generator () takes exactly 2 arguments (1 given)

我希望这两项活动都能成功。在我看来,这适用于window.bindbutton_003.bind ("<ButtonRelease-1>", Generating_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)

Tags: textoutputgetdatetimebindbuttongeneratorean
2条回答

您可以尝试以下方法:

class Generator:
    def generator(self, event=None):  # <- give event a default value.
        ...

我认为您的类中需要一个__init__函数:

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

然后您可以将self.event用于事件

相关问题 更多 >