面向对象GUI

from tkinter import *
from tkinter.ttk import *

#整个窗体的GUI就是一个类


class Calculator:  #继承Tk
    def __init__(self):
        self.frame=Tk()  #通过Tk实例化一个对象。
        self.frame.title("计算器")  #对象.继承类的属性
        self.frame.geometry("700x200+300+250")#对象.继承类的属性
        self.frame.resizable()#对象.继承类的属性
        self.frame["bg"]="darkgray"#对象.继承类的属性

        self.Entry_num01=Entry(self.frame,font=("微软雅黑",14,"bold"),width=10)  #添加一个文本输入框。--number01
        self.Entry_num01.place(x=20,y=80)
#添加一个下拉框的运算
        self.action=Combobox(self.frame,font=("微软雅黑",14,"bold"),width=4,)
#style配置字体
        self.style01=Style()
        self.style01.configure("TButton",font=("微软雅黑",14,"bold"),foreground="navy")



        self.action["values"]=["加[+]","减[-]","乘[x]","除[/]","余[%]"]
        self.action["state"]="readonly" #读
        self.action.current(0)
        self.action.place(x=170, y=80)
        #添加一个num02的文本框
        self.Entry_num02=Entry(self.frame,font=("微软雅黑",14,"bold"),width=10)  #添加一个文本输入框。--number01
        self.Entry_num02.place(x=270,y=80)

        # 添加一个num02的文本框
        self.Label_result = Label(self.frame, text='=',font=("微软雅黑", 14, "bold"), width=4)  # 添加一个文本输入框。--number01
        self.Label_result.place(x=410, y=80)

        # 添加一个结果的文本框
        self.Entry_result = Entry(self.frame, state=DISABLED, font=("微软雅黑", 14, "bold"), width=4)  # 添加一个文本输入框。--number01
        self.Entry_result.place(x=520, y=80)

        # 显示计算按钮
        self.Button_cal = Button(self.frame, text="计算",width=6,command=self.number_cal)  # 添加一个文本输入框。--number01
        self.Button_cal.place(x=600, y=80)

    def show(self):
        self.frame.mainloop()
    def add(self):
        pass
    def div(self):
        pass
    def number_cal(self):
        pass

if __name__=="__main__":
    my_calculator=Calculator()
    my_calculator.show()

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值