可以将输入转换成数字

2024-04-20 04:26:39 发布

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

__author__ = 'Feuer'
from tkinter import *

root = Tk()
root.geometry("750x400")


def stop():
    exit()


def plus():
    global erg11
    erg11 = z1 + z2


class Start:
    def __init__(self, master):
        frame = Frame(master)
        frame.pack()

        self.Label_1 = Label(frame, text="Bitte wählen Sie die Rechenart aus, die Sie benutzen möchten!")
        self.Label_2 = Label(frame, text="Addition")
        self.Label_3 = Label(frame, text="Subtraktion")
        self.Label_4 = Label(frame, text="Multiplikation")
        self.Label_5 = Label(frame, text="Division")
        self.Label_6 = Label(frame, text="Wurzel")
        self.Label_7 = Label(frame, text="Logarithmus")
        self.Button_1 = Button(frame, text="Go!", command=Add)
        self.Button_2 = Button(frame, text="Go!")
        self.Button_3 = Button(frame, text="Go!")
        self.Button_4 = Button(frame, text="Go!")
        self.Button_5 = Button(frame, text="Go!")
        self.Button_6 = Button(frame, text="Go!")
        self.Button_7 = Button(frame, text="Das Programm beenden!", command=stop)

        self.Label_1.grid(row=0, columnspan=2)
        self.Label_2.grid(row=1, column=0)
        self.Label_3.grid(row=2, column=0)
        self.Label_4.grid(row=3, column=0)
        self.Label_5.grid(row=4, column=0)
        self.Label_6.grid(row=5, column=0)
        self.Label_7.grid(row=6, column=0)
        self.Button_1.grid(row=1, column=1)
        self.Button_2.grid(row=2, column=1)
        self.Button_3.grid(row=3, column=1)
        self.Button_4.grid(row=4, column=1)
        self.Button_5.grid(row=5, column=1)
        self.Button_6.grid(row=6, column=1)
        self.Button_7.grid(row=7, columnspan=2)


class Add:
    def __init__(self):
        newwin = Toplevel()
        newwin.geometry("750x400")
        frame2 = Frame(newwin)
        frame2.pack()

        global erg11

        global z1
        global z2

        erg11 = "Ready"

        self.Label_1 = Label(frame2, text="Additionsverfahren")
        self.Entry_1 = Entry(frame2)
        self.Label_2 = Label(frame2, text="+")
        self.Entry_2 = Entry(frame2)
        self.Label_3 = Label(frame2, text="=")
        self.Button_1 = Button(frame2, text="Zurück", command=newwin.destroy)
        self.Button_2 = Button(frame2, text="Ergebniss berechnen")
        self.Label_Erg1 = Label(frame2, text=erg11)

        self.Button_2.bind("<Button-1>", plus)

        self.Label_1.grid(row=0, columnspan=4)
        self.Entry_1.grid(row=1, column=0)
        self.Label_2.grid(row=1, column=1)
        self.Entry_2.grid(row=1, column=2)
        self.Label_3.grid(row=1, column=3)
        self.Button_2.grid(row=2, columnspan=4)
        self.Button_1.grid(row=3, columnspan=4)
        self.Label_Erg1.grid(row=1, column=4)









app = Start(root)
root.mainloop()

这是我目前正在使用的代码,我试图用Python的gui创建一个无用的计算器。当有人按下按钮2(在第二个类中)时,我不知道如何从条目1和2中取出变量(z1/z1)。有人能给我一些代码来修复它吗?你知道吗


编辑:
我编辑了代码,每个人都可以尝试为我的问题找到解决方案,因为我的解决方案以僵局告终。(艾尔斯)


Tags: textselfgodefcolumnbuttonrootframe