重命名级联选项,删除选项和选中选项

时间:2017-11-25 14:54:11

标签: python-3.x tkinter rename cascade checked

好吧,我正在用Python和Tkinter制作一个计算器,它正在工作,但是我想添加一个'语言'选项,你可以在这里更改程序的语言,我想知道如何重命名add_comand标签。 ..

以及如何删除将级联转换为窗口的选项? “------”选项?

最后,当你点击时,我需要做什么来在级联选项的侧面出现'已检查'图标?

CODE:

from tkinter import *
from math import *

n1=0
op=""
n2=0
dt=False
col=False

#FUNÇÕES
def number(n):
    lb["text"]+=str(n)

def operation(o):
    global dt
    global op
    global n1

    if lb["text"]!="":
        if dt==False:
            n1=int(lb["text"])
        elif dt==True:
            n1=float(lb["text"])
        lb["text"] = ""
        op = str(o)
        dt=False
    else:
        if o=="+" or o=="-":
            lb["text"]+=o

def c():
    global n1
    global n2
    global op
    global dt
    n1=0
    n2=0
    op=""
    dt=False
    lb["text"]=""

def dot():
    global dt
    if dt==False:
        lb["text"]+="."
        dt=True

def result():
    global n1
    global n2
    global op
    global dt

    if dt==False:
        n2=int(lb["text"])
    elif dt==True:
        n2=float(lb["text"])

    if op=='+':
        lb["text"]=str(n1+n2)
    elif op=='-':
        lb["text"]=str(n1-n2)
    elif op=='*':
        lb["text"]=str(n1*n2)
    elif op=='/':
        lb["text"]=str(n1/n2)
        dt=True

def color(t):
    if t==1:
        janela["bg"]='#f2f2f2'
        bt0['bg'] = '#f2f2f2'
        bt1['bg'] = '#f2f2f2'
        bt2['bg'] = '#f2f2f2'
        bt3['bg'] = '#f2f2f2'
        bt4['bg'] = '#f2f2f2'
        bt5['bg'] = '#f2f2f2'
        bt6['bg'] = '#f2f2f2'
        bt7['bg'] = '#f2f2f2'
        bt8['bg'] = '#f2f2f2'
        bt9['bg'] = '#f2f2f2'
        bta['bg'] = '#f2f2f2'
        bts['bg'] = '#f2f2f2'
        btm['bg'] = '#f2f2f2'
        btd['bg'] = '#f2f2f2'
        btc['bg'] = '#f2f2f2'
        btp['bg'] = '#f2f2f2'
        btr['bg'] = '#f2f2f2'
    if t==2:
        janela["bg"]='orange'
        bt0['bg'] = '#f2f2f2'
        bt1['bg'] = '#f2f2f2'
        bt2['bg'] = '#f2f2f2'
        bt3['bg'] = '#f2f2f2'
        bt4['bg'] = '#f2f2f2'
        bt5['bg'] = '#f2f2f2'
        bt6['bg'] = '#f2f2f2'
        bt7['bg'] = '#f2f2f2'
        bt8['bg'] = '#f2f2f2'
        bt9['bg'] = '#f2f2f2'
        bta['bg'] = '#f2f2f2'
        bts['bg'] = '#f2f2f2'
        btm['bg'] = '#f2f2f2'
        btd['bg'] = '#f2f2f2'
        btc['bg'] = '#f2f2f2'
        btp['bg'] = '#f2f2f2'
        btr['bg'] = '#f2f2f2'
    if t==3:
        janela["bg"]='black'
        bt0['bg']='gray'
        bt1['bg']='gray'
        bt2['bg']='gray'
        bt3['bg']='gray'
        bt4['bg']='gray'
        bt5['bg']='gray'
        bt6['bg']='gray'
        bt7['bg']='gray'
        bt8['bg']='gray'
        bt9['bg']='gray'
        bta['bg']='gray'
        bts['bg']='gray'
        btm['bg']='gray'
        btd['bg']='gray'
        btc['bg']='gray'
        btp['bg']='gray'
        btr['bg']='gray'
    if t==4:
        janela["bg"]='black'
        bt0['bg']='#009933'
        bt1['bg']='#009933'
        bt2['bg']='#009933'
        bt3['bg']='#009933'
        bt4['bg']='#009933'
        bt5['bg']='#009933'
        bt6['bg']='#009933'
        bt7['bg']='#009933'
        bt8['bg']='#009933'
        bt9['bg']='#009933'
        bta['bg']='#009933'
        bts['bg']='#009933'
        btm['bg']='#009933'
        btd['bg']='#009933'
        btc['bg']='#009933'
        btp['bg']='#009933'
        btr['bg']='#009933'
    if t==5:
        janela["bg"]='#ddf9ff'
        bt0['bg'] = '#b5e3ff'
        bt1['bg'] = '#b5e3ff'
        bt2['bg'] = '#b5e3ff'
        bt3['bg'] = '#b5e3ff'
        bt4['bg'] = '#b5e3ff'
        bt5['bg'] = '#b5e3ff'
        bt6['bg'] = '#b5e3ff'
        bt7['bg'] = '#b5e3ff'
        bt8['bg'] = '#b5e3ff'
        bt9['bg'] = '#b5e3ff'
        bta['bg'] = '#b5e3ff'
        bts['bg'] = '#b5e3ff'
        btm['bg'] = '#b5e3ff'
        btd['bg'] = '#b5e3ff'
        btc['bg'] = '#b5e3ff'
        btp['bg'] = '#b5e3ff'
        btr['bg'] = '#b5e3ff'

def colbot():
    global col

    if col==False:
        col=True

    if col==True:
        col=False

    print(col)

def lang(l):
    if l==1:
        janela.title("Calculator")
    if l==2:
        janela.title("Calculadora")


#JANELA
janela = Tk()

janela.title("Calculator")
janela.geometry("205x305+300+300")
janela.resizable(0,0)
janela.attributes("-toolwindow")
janela.iconbitmap(default='PI.ico')
janela["bg"]='orange'

#MENUS
bar=Menu(janela)
janela.config(menu=bar)

#View
view=Menu(bar)
bar.add_cascade(label='View', menu=view)
theme=Menu(view)
language=Menu(view)

#View-Theme
view.add_cascade(label='Theme', menu=theme)
theme.add_command(label='Old', command=lambda:color(1))
theme.add_command(label='Default', command=lambda:color(2))
theme.add_command(label='Dark', command=lambda:color(3))
theme.add_command(label='Hacker', command=lambda:color(4))
theme.add_command(label='Blue', command=lambda:color(5))
theme.add_separator()
theme.add_command(label='Colored Buttons', command=colbot)
theme.add_checkbutton(label="YY")

#View-Language
view.add_cascade(label="Language", menu=language)
language.add_command(label="English", command=lambda:lang(1))
language.add_command(label="Português", command=lambda:lang(2))
language.add_command(label="Español", command=lambda:lang(3))

#BOTÕES
lb=Label(janela, width=27, height=2, text="", bg='white')

bt1=Button(janela, text="1", width=5, height=2, command=lambda:number(1))
bt2=Button(janela, text="2", width=5, height=2, command=lambda:number(2))
bt3=Button(janela, text="3", width=5, height=2, command=lambda:number(3))
bt4=Button(janela, text="4", width=5, height=2, command=lambda:number(4))
bt5=Button(janela, text="5", width=5, height=2, command=lambda:number(5))
bt6=Button(janela, text="6", width=5, height=2, command=lambda:number(6))
bt7=Button(janela, text="7", width=5, height=2, command=lambda:number(7))
bt8=Button(janela, text="8", width=5, height=2, command=lambda:number(8))
bt9=Button(janela, text="9", width=5, height=2, command=lambda:number(9))
bt0=Button(janela, text="0", width=12, height=2, command=lambda:number(0))

btp=Button(janela, text=".", width=5, height=2 ,command=dot)

bta=Button(janela, text="+", width=5, height=2, bg='#cccccc', command=lambda:operation('+'))
bts=Button(janela, text="-", width=5, height=2, bg='#cccccc', command=lambda:operation('-'))
btm=Button(janela, text="x", width=5, height=2, bg='#cccccc', command=lambda:operation('*'))
btd=Button(janela, text="/", width=5, height=2, bg='#cccccc', command=lambda:operation('/'))

btr=Button(janela, text="=", width=19, height=2 ,command=result)
btc=Button(janela, text="C", width=5, height=2, command=c, bg='#cccccc')


#POSIÇÃO
lb.place(x=5,y=5)

bt1.place(x=5,   y=55)
bt2.place(x=55,  y=55)
bt3.place(x=105, y=55)
bt4.place(x=5,   y=105)
bt5.place(x=55,  y=105)
bt6.place(x=105, y=105)
bt7.place(x=5,   y=155)
bt8.place(x=55,  y=155)
bt9.place(x=105, y=155)
bt0.place(x=5,   y=205)

btp.place(x=105, y=205)

bta.place(x=155, y=55)
bts.place(x=155, y=105)
btm.place(x=155, y=155)
btd.place(x=155, y=205)

btr.place(x=5,   y=255)
btc.place(x=155, y=255)

janela.mainloop()

0 个答案:

没有答案