会员可以在此提问,百战程序员老师有问必答
对大家有帮助的问答会被标记为“推荐”
看完课程过来浏览一下别人提的问题,会帮你学得更全面
截止目前,同学们一共提了 132654个问题
Python 全系列/第二阶段:Python 深入与提高/异常机制 1426楼
Python 全系列/第二阶段:Python 深入与提高/坦克大战 1427楼

屏幕截图 2024-09-28 165117.png

Python 全系列/第二阶段:Python 深入与提高/坦克大战 1428楼

from tkinter import*
from tkinter import messagebox
class Application(Frame):
    def __init__(self,master=None):
        super().__init__(master)
        self.master=master
        self.createwidget()

    def createwidget(self):
        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):
            #print(r)
            for cindex,c in enumerate(r):
                #print(c)
                if c=="=":
                    Button(self,text=c,width=2).grid(row=rindex+1,column=cindex,
                                                            rowspan=2,sticky="ew")
                elif c==0:
                    Button(self,text=c,width=2).grid(row=rindex+1,column=cindex,
                                                            columnspan=2,sticky="ew")
                elif c==".":
                    Button(self,text=c,width=2).grid(row=rindex+1,column=cindex,sticky="ew")
                else:
                    Button(self,text=c,width=2).grid(row=rindex+1,column=cindex,sticky="ew")


if __name__=="__main__":
    root=Tk()
    root.geometry("500x700+400+200")
    root.title("计算器")
    app=Application(master=root)
    root.mainloop()

老师,我的代码跟老师视频里的一样,为什么我运行的不显示呢image.png

Python 全系列/第二阶段:Python 深入与提高/GUI编程(隐藏) 1429楼
Python 全系列/第二阶段:Python 深入与提高/(旧)坦克大战 1431楼
Python 全系列/第二阶段:Python 深入与提高/文件处理 1432楼
Python 全系列/第二阶段:Python 深入与提高/GUI编程(隐藏) 1434楼
Python 全系列/第二阶段:Python 深入与提高/坦克大战 1435楼

image.png

Python 全系列/第二阶段:Python 深入与提高/模块 1436楼
Python 全系列/第二阶段:Python 深入与提高/异常机制 1437楼
Python 全系列/第二阶段:Python 深入与提高/GUI编程(隐藏) 1439楼

课程分类

百战程序员微信公众号

百战程序员微信小程序

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