내 코드를 편집하도록 요청 받았다 프로그램 내에서 레이블을 변경하는 방법 그래서 환영 레이블 텍스트가 늘 따라 변경하는 것이 무슨 잘못 전체 계산기 스크립트Tkinter를 : 자체
from tkinter import * global choice choice = 0 #Program def calculate(*event): if choice == 1: try: add1 = ccalc1.get() add2 = ccalc2.get() except: no = Label(app, text="You must use a number").grid(row=0, column=0) answ = add1 + add2 answer = Label(app, text = answ).grid(row=1, column=0) elif choice == 2: try: sub1 = ccalc1.get() sub2 = ccalc2.get() except: no = Label(app, text="You must use a number").grid(row=1, column=0) answ = sub1 - sub2 answer = Label(app, text = answ).grid(row=1, column=0) def choice2(): global choice choice = 2 #End Program #GUI #Window Info calc = Tk() calc.title("Calculator") calc.geometry("200x140") #End Window Info #Build Window app = Frame(calc) app.grid() ccalc1 = IntVar() ccalc2 = IntVar() #Widgets if choice == 0: welcome = Label(app, text="Select a choice") elif choice == 2: welcome.config(text="Subtraction") calcbox1 = Entry(app,textvariable=ccalc1) calcbox2 = Entry(app,textvariable=ccalc2) submit = Button(app, text="CALCULATE", command = calculate) welcome.grid(row=0,column=0) calcbox1.grid(row=2, column=0) calcbox2.grid(row=3, column=0) submit.grid(row=4, column=0) calc.bind('<Return>', calculate) #End Widgets #Menu menu=Menu(calc) #Operations filemenu = Menu(menu,tearoff=0) filemenu.add_command(label="Subtract", command = choice2) menu.add_cascade(label="Operations",menu=filemenu) calc.config(menu=menu) calc.mainloop() #End GUI
을 포함하기로 결정했다.
업데이트 : 전체 계산기 코드를 포함합니다.
도움이 되었습니까?
여기에 게시 한 코드를 다시 한 번 확인하시기 바랍니다. 나는 그것을 실행하려하고'IndentationError : unindent가 임의의 외부 들여 쓰기 레벨과 일치하지 않습니다. ' – Kevin
전체 계산기가 포함되도록 업데이트되었습니다. 그것은 나를 위해 작동합니다 – user3763447
메뉴에서 선택한 후 '선택 선택'을 '빼기'로 변경하면 발생합니다. – user3763447