计算器软件界面的设计


计算器软件界面设计

# coding=utf-8

"""计算器软件界面的设计"""

from tkinter import *
from tkinter import messagebox
import random

class Application(Frame):

    def __init__(self, master=None):
        super().__init__(master)
        self.master = master
        self.pack()
        self.create_widget()

    def create_widget(self):
        """通过grid布局实现计算器的界面"""
        btnText = (("MC", "M+", "M-", "MR"),
                   ("C", "±", "/", "×"),
                   (7, 8, 9, "-"),
                   (4, 5, 6, "+"),
                   (1, 2, 3, "="),
                   (0, "."))

        Entry(self).grid(row=0, column=0, columnspan=4, pady=10)

        for rindex,r in enumerate(btnText):
            for cindex,c in enumerate(r):
                if c == "=":
                    Button(self, text=c, width=2).grid(row=rindex+ 1, column=cindex, rowspan=2, sticky=NSEW)
                elif c == 0:
                    Button(self, text=c, width=2).grid(row=rindex + 1, column=cindex, columnspan=2, sticky=NSEW)
                elif c == ".":
                    Button(self, text=c, width=2).grid(row=rindex + 1, column=cindex + 1, sticky=NSEW)
                else:
                    Button(self, text=c, width=2).grid(row=rindex + 1, column=cindex, sticky=NSEW)

    def confirm(self):
        pass

if __name__ == '__main__':
    root = Tk()
    root.geometry("200x250+200+300")
    app = Application(master=root)
    root.mainloop()


扫描二维码,在手机上阅读

开发一个简单的记事本

测试一个经典的GUI程序写法,使用面向对象方式

评 论
更换验证码