❓ Help python calculator

Status
Not open for further replies.

Megabing213

Established
pwede po pafix? ayaw kasi mag function nung mga button ilagay sana sa entry kapag napipindot pero ayaw. thanks


import tkinter

class MyGUI:
def __init__(self):
self.root = tkinter.Tk()
self.root.title("CALCULATOR")

self.topFrame = tkinter.Frame(self.root)
self.midFrame = tkinter.Frame(self.root)
self.bottomFrame = tkinter.Frame(self.root)
self.centerFrame = tkinter.Frame(self.root)
self.bottom2Frame = tkinter.Frame(self.root)
self.bottom3Frame = tkinter.Frame(self.root)

#entry
self.Entry = tkinter.Entry(self.topFrame, width = 30, borderwidth = 10)

#buttons
self.Button_1 = tkinter.Button(self.midFrame, text = "1", width = 5, height = 5)
self.Button_2 = tkinter.Button(self.midFrame, text = "2", width = 5, height = 5)
self.ButtonPlus = tkinter.Button(self.midFrame, text = "+", width = 5, height = 5)
self.Button_4 = tkinter.Button(self.bottomFrame, text = "4", width = 5, height = 5)
self.Button_5 = tkinter.Button(self.bottomFrame, text = "5", width = 5, height = 5)
self.Button_6 = tkinter.Button(self.bottomFrame, text = "6", width = 5, height = 5)
self.Button_Sub = tkinter.Button(self.bottomFrame, text = "-", width = 5, height = 5)
self.Button_7 = tkinter.Button(self.centerFrame, text = "7", width = 5, height = 5)
self.Button_8 = tkinter.Button(self.centerFrame, text = "8", width = 5, height = 5)
self.Button_9 = tkinter.Button(self.centerFrame, text = "9", width = 5, height = 5)
self.Button_Multi = tkinter.Button(self.centerFrame, text = "*", width = 5, height = 5)
self.Button_Clr = tkinter.Button(self.bottom2Frame, text = "Clr", width = 5, height = 5)
self.Button_0 = tkinter.Button(self.bottom2Frame, text = "0", width = 5, height = 5)
self.Button_Dot = tkinter.Button(self.bottom2Frame, text = ".", width = 5, height = 5)
self.Button_Div = tkinter.Button(self.bottom2Frame, text = "/", width = 5, height = 5)
self.Button_Equal = tkinter.Button(self.bottom3Frame, text = "=", width = 32, height = 5,\
bg = "orange", borderwidth = "2")


#mainfunction

def button_func(self):
self.topFrame, current = tkinter.Entry.get()
self.Entry.insert(0, str(current) + str())
#function
self.button_1 = tkinter.Button(self.midFrame, command = lambda: button_func(1))
self.button_2 = tkinter.Button(self.midFrame, command = lambda: button_func(2))
self.button_3 = tkinter.Button(self.midFrame, command = lambda: button_func(3))
self.button_4 = tkinter.Button(self.bottomFrame, command = lambda: button_func(4))
self.button_5 = tkinter.Button(self.bottomFrame, command = lambda: button_func(5))
self.button_6 = tkinter.Button(self.bottomFrame, command = lambda: button_func(6))
self.button_7 = tkinter.Button(self.centerFrame, command = lambda: button_func(7))
self.button_8 = tkinter.Button(self.centerFrame, command = lambda: button_func(8))
self.button_9 = tkinter.Button(self.centerFrame, command = lambda: button_func(9))
self.button_0 = tkinter.Button(self.bottom2Frame, command = lambda: button_func(0))
#packing
self.Entry.pack(side="left")
self.Button_1.pack(side="left")
self.Button_2.pack(side="left")
self.Button_3.pack(side="left")
self.ButtonPlus.pack(side="left")
self.Button_4.pack(side = "left")
self.Button_5.pack(side = "left")
self.Button_6.pack(side = "left")
self.Button_Sub.pack(side = "left")
self.Button_7.pack(side = "left")
self.Button_8.pack(side = "left")
self.Button_9.pack(side = "left")
self.Button_Multi.pack(side = "left")
self.Button_Clr.pack(side = "left")
self.Button_0.pack(side = "left")
self.Button_Dot.pack(side = "left")
self.Button_Div.pack(side = "left")
self.Button_Equal.pack(side = "left")

#framepacking
self.topFrame.pack()
self.Entry.pack()
self.midFrame.pack()
self.bottomFrame.pack()
self.centerFrame.pack()
self.bottom2Frame.pack()
self.bottom3Frame.pack()
tkinter.mainloop()
my_gui = MyGUI()
 
Status
Not open for further replies.

About this Thread

  • 0
    Replies
  • 426
    Views
  • 1
    Participants
Last reply from:
Megabing213

Trending Topics

Online now

Members online
1,083
Guests online
8,858
Total visitors
9,941

Forum statistics

Threads
2,354,243
Posts
29,382,859
Members
1,079,384
Latest member
chuerys
Back
Top