0
from Tkinter import *
class Calc():
def_init_(self):
self.total = 0
self.current = ""
self.new_num = True
self.op_pending = False
self.op = ""
self.eq_flag = False
def num_press(self, num):
temp = text_box.get()
self.eq_flag = False
temp2 = str(num)
if self.new_num == True:
self.current = temp2
self.new_num = False
else:
if temp2 == '.':
if temp2 in temp:
return
self.current = temp + temp2
text_box.delete(0, END)
text_box.insert(0, self.current)
def calc_total(self):
if self.op_pending == True:
self.do_sum()
self.op_pending = False
def do_sum(self):
self.current = float(self.current)
if self.op == "add":
self.total += self.current
if self.op == "minus":
self.total -= self.current
if self.op == "times":
self.total *= self.current
if self.op == "divide":
self.total /= self.current
text_box.delete(0, END)
text_box.insert(0, self.total)
self.new_num = True
def operation(self, op):
if self.op_pending == True:
self.do_sum()
self.op = op
else:
self.op_pending = True
if self.eq_flag == False:
self.total = float(text_box.get())
else:
self.total = self.current
self.new_sum = True
self.op = op
self.eq_flag = False
def cancel(self):
text_box.delete(0, END)
text_box.insert(0, "0")
self.new_num = True
def all_cancel(self):
self.cancel()
self.total = 0
def sign(self):
self.current = -(float(text_box.get()))
text_box.delete(0, END)
text_box.insert(0, self.current())
numbers = "789456123"
i = 0
bttn= []
for k in range(1,4):
for k in range(3):
bttn.append(Button(calc, text = numbers[i]))
bttn[i].grid(row = j, column = k, pady = 5)
bttn[i]["command"] = lambda x = numbers[i]: sum1.num_press(x)
i += 1
내가 파이썬 3.3를 시도했다
과 2.7 모두 후 구문 오류라고 'def_init_ (자기) :' 어떤 수정이나 뭔가가 있나요? 미리 감사드립니다.파이썬 Tkinter를 계산
가 링크에 여기 아닌 코드를 게시하시기 바랍니다 (
calc
가 글로벌 범위에서 정의되지 않았기 때문에 여전히 실행되지 않습니다 있지만)귀하의 프로그램은 문법적으로 정확합니다. 너무 길면 관련 부품 만 게시하십시오. – iCodez
죄송합니다, 전 stackoverflow.com 게시 – user3250207