GUI计算器中的Shift按钮

时间:2017-09-21 20:16:19

标签: python user-interface

我浏览了这个网站,但我找不到一个问题,可以帮助我了解如何在我的计算器代码中输入一个班次按钮。你能帮忙吗?

from tkinter import*

mode = 0

def ShiftUse(mode):
    ?????????
     text_Input.set(mode)
     return


def btnUse(numbers):
    global operator
    operator=operator + str(numbers)
    text_Input.set(operator)

def btnClearUse():
    global operator
    operator=''
    text_Input.set('')

def btnEaqualsUse():
    global operator
    sumup=str(eval(operator))
    text_Input.set(sumup)
    operator=''

calc = Tk()
calc.title('Calculator')
operator=''
text_Input =StringVar()

textDisplay = Entry(calc, font=('arial', 20, 'bold'), textvariable=text_Input, bd=30, insertwidth=4, bg='powder blue', justify='right').grid(columnspan=4)#=Work
    btn7=Button(calc,padx=16,pady=8,bd=8, fg='black',font=('arial', 20,'bold'), text='7', bg='powder blue',command=lambda:btnUse(7)).grid(row=1,column=0)#=Work

btn8=Button(calc,padx=16,pady=8,bd=8, fg='black',font=('arial', 20,'bold'), text='8', bg='powder blue',command=lambda:btnUse(8)).grid(row=1,column=1)#=Work

btn9=Button(calc,padx=16,pady=8,bd=8, fg='black',font=('arial', 20,'bold'), text='9', bg='powder blue',command=lambda:btnUse(9)).grid(row=1,column=2)#=Work

Plus=Button(calc,padx=16,pady=8,bd=8, fg='black',font=('arial', 20,'bold'), text='+', bg='powder blue',command=lambda:btnUse('+')).grid(row=1,column=3)#=Work

btn4=Button(calc,padx=16,pady=8,bd=8, fg='black',font=('arial', 20,'bold'), text='4', bg='powder blue',command=lambda:btnUse(4)).grid(row=2,column=0)#=Work

btn5=Button(calc,padx=16,pady=8,bd=8, fg='black',font=('arial', 20,'bold'), text='5', bg='powder blue',command=lambda:btnUse(5)).grid(row=2,column=1)#=Work

btn6=Button(calc,padx=16,pady=8,bd=8, fg='black',font=('arial', 20,'bold'), text='6', bg='powder blue',command=lambda:btnUse(6)).grid(row=2,column=2)#=Work

Subtract=Button(calc,padx=16,pady=8,bd=8, fg='black',font=('arial', 20,'bold'), text='–', bg='powder blue',command=lambda:btnUse('-')).grid(row=2,column=3)#=Work

btn1=Button(calc,padx=16,pady=8,bd=8, fg='black',font=('arial', 20,'bold'), text='1', bg='powder blue',command=lambda:btnUse(1)).grid(row=3,column=0)#=Work

btn2=Button(calc,padx=16,pady=8,bd=8, fg='black',font=('arial', 20,'bold'), text='2', bg='powder blue',command=lambda:btnUse(2)).grid(row=3,column=1)#=Work

btn3=Button(calc,padx=16,pady=8,bd=8, fg='black',font=('arial', 20,'bold'), text='3', bg='powder blue',command=lambda:btnUse(3)).grid(row=3,column=2)#=Work

Times=Button(calc,padx=16,pady=8,bd=8, fg='black',font=('arial', 20,'bold'), text='x', bg='powder blue',command=lambda:btnUse('*')).grid(row=3,column=3)#=Work

Sqr=Button(calc,padx=9,pady=8,bd=8, fg='black',font=('arial', 20,'bold'), text='x₂', bg='powder blue',command=lambda:btnUse('**2')).grid(row=4,column=0)#=Work

btn0=Button(calc,padx=16,pady=8,bd=8, fg='black',font=('arial', 20,'bold'), text='0', bg='powder blue',command=lambda:btnUse(0)).grid(row=4,column=1)#=Work

Squroot=Button(calc,padx=16,pady=8,bd=8, fg='black',font=('arial', 20,'bold'), text='√', bg='powder blue',command=lambda:btnUse('**(1/2.0)')).grid(row=4,column=2)#=Work

Divide=Button(calc,padx=16,pady=8,bd=8, fg='black',font=('arial', 20,'bold'), text='÷', bg='powder blue',command=lambda:btnUse('/')).grid(row=4,column=3)#=Work

Clear=Button(calc,padx=14,pady=16,bd=8, fg='black',font=('arial', 20,'bold'), text='C', bg='powder blue',command=btnClearUse).grid(row=5,column=0)#=Work

Decimal=Button(calc,padx=19,pady=16,bd=8, fg='black',font=('arial', 20,'bold'), text='.', bg='powder blue',command=lambda:btnUse('.')).grid(row=5,column=1)#=Work

Pie=Button(calc,padx=13,pady=16,bd=8, fg='black',font=('arial', 20,'bold'), text='π', bg='powder blue',command=lambda:btnUse(3.14159)).grid(row=5,column=2)#=Work

Eaquals=Button(calc,padx=16,pady=16,bd=8, fg='black',font=('arial', 20,'bold'), text='=', bg='powder blue',command=btnEaqualsUse).grid(row=5,column=3)#=Work

Shift=Button(calc,padx=16,pady=16,bd=8, fg='black',font=('arial', 20,'bold'), text='sft', bg='powder blue',command=ShiftUse(1)).grid(row=6,column=0)

calc.mainloop()

我创建了这个功能和按钮,我根本不知道如何让按钮将所有其他值切换到我选择的其他值。这可能是显而易见的,当我得到答案时我可能会踢自己,但我仍然会帮助你。

0 个答案:

没有答案