会员可以在此提问,百战程序员老师有问必答
对大家有帮助的问答会被标记为“推荐”
看完课程过来浏览一下别人提的问题,会帮你学得更全面
截止目前,同学们一共提了 132600个问题
JAVA 全系列/第十九阶段:Spring Cloud微服务技术栈/Spring Cloud(旧) 26986楼
Python 全系列/第一阶段:Python入门/面向对象 26988楼
Python 全系列/第二阶段:Python 深入与提高/GUI编程(隐藏) 26990楼
JAVA 全系列/第十一阶段:智能家居项目(旧)/至尊智能家居第二天 26992楼
Python 全系列/第二阶段:Python 深入与提高/GUI编程(隐藏) 26993楼
人工智能/第五阶段:机器学习-线性回归/多元线性回归 26995楼

from tkinter import *


class Application(Frame):
    def __init__(self, master=None):
        super().__init__(master)
        self.master = master
        self.pack()
        self.creatWidget()

    def creatWidget(self):
        '''通过 grid 布局实现简易计算器'''
        btntext = (('MC', 'M+', 'M-', 'MR'),
                   ('C', '±', '÷', '×'),
                   (7, 8 , 9 , '-'),
                   (4, 5, 6, '+'),
                   (1, 2, 3, '='),
                   (0, '.'))
        self.entry01 = Entry(self)
        self.entry01.grid(row=0, columnspan=4, pady =10)
        # pady 表示距下面的按钮 10 个像素

        for rindex,r in enumerate(btntext):
            for cindex,c in enumerate(r):
                if c == '=':
                    Button(self, text=c, width=2).grid(rows=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)


if __name__ == '__main__':
    root = Tk()
    root.geometry('170x230+200+200')
    root.title('简易计算器界面')
    app = Application(master=root)
    root.mainloop()


运行结果:

image.png


问题:

老师,我检查了很久,没有检查出来这个  ’=‘ 为什么没有跨行,请帮忙看一下,谢谢~

Python 全系列/第二阶段:Python 深入与提高/GUI编程(隐藏) 26997楼
Python 全系列/第一阶段:Python入门/函数和内存分析 27000楼

课程分类

百战程序员微信公众号

百战程序员微信小程序

©2014-2025百战汇智(北京)科技有限公司 All Rights Reserved 北京亦庄经济开发区科创十四街 赛蒂国际工业园
网站维护:百战汇智(北京)科技有限公司
京公网安备 11011402011233号    京ICP备18060230号-3    营业执照    经营许可证:京B2-20212637