会员可以在此提问,百战程序员老师有问必答
对大家有帮助的问答会被标记为“推荐”
看完课程过来浏览一下别人提的问题,会帮你学得更全面
截止目前,同学们一共提了 132456个问题
JAVA 全系列/第十四阶段:海量数据存储与查询/MyCat(旧) 9632楼

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编程(隐藏) 9636楼
Python 全系列/第五阶段:数据库编程/MySQL数据库的使用 9637楼
WEB前端全系列/第二十阶段:Vue2企业级项目(旧)/易购商品后台管理系统 9638楼
JAVA 全系列/第二阶段:JAVA 基础深化和提高/网络编程(旧) 9640楼
Python 全系列/第三阶段:Python 网络与并发编程/并发编程 9642楼
JAVA 全系列/第二阶段:JAVA 基础深化和提高/智能电话本项目实战 9643楼
Python 全系列/第五阶段:数据库编程/MySQL数据库的使用 9645楼

课程分类

百战程序员微信公众号

百战程序员微信小程序

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