会员可以在此提问,百战程序员老师有问必答
对大家有帮助的问答会被标记为“推荐”
看完课程过来浏览一下别人提的问题,会帮你学得更全面
截止目前,同学们一共提了 133642个问题
JAVA 全系列/第六阶段:JavaWeb开发/Servlet技术详解(旧) 28081楼

代码:

"""测试一个grid布局"""

from tkinter import *
from tkinter import messagebox

class Application(Frame):
    """一个经典的GUI程序的类的写法"""
    def __init__(self, master=None):
        super().__init__(master)  # super()代表的是父类的定义,而不是父类对象
        self.master = master
        self.pack()
        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):
            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)

if __name__ =='__main__':
    root = Tk()
    root.geometry("190x235+1300-400")
    app = Application(master=root)
    root.mainloop()

疑问01.png

老师,我按照视频上的代码敲了一遍,为什么0没有跨列呢?

Python 全系列/第二阶段:Python 深入与提高/GUI编程(隐藏) 28083楼
Python 全系列/第三阶段:Python 网络与并发编程/网络通信 28086楼

from tkinter import *
from tkinter import messagebox


class Application(Frame):
    """一个经典的GUI程序的类的写法"""

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

    def createWidge(self):
        """创建组件"""
        self.label01 = Label(self, text="北京尚学堂", width=10,
                             height=2, bg="black", fg="white")
        self.label01.pack()
        self.label02 = Label(self, text="百战程序员", width=10,
                             height=2, bg="red", fg="blue", font=("仿宋", 30))
        self.label02.pack()
        self.label03 = Label(self, text="高淇老师\nPYTHON专家\n有一个儿子叫高晓曦",
                             font=("宋体", 40), relief="solid", borderwidth=3, justify="left")
        self.label03.pack()
        # 测试图片加载
        global photo
        photo = PhotoImage(file="imgs\logo.gif")    #如果在这里输入绝对路径,可以正常显示,但是相对路径不行。
        self.label04 = Label(image=photo)
        self.label04.pack()


if __name__ == '__main__':
    root = Tk()
    root.geometry("888x555+200+200")
    root.title("测试label")
    Application(master=root)
    root.mainloop()

image.png

老师帮忙看看是什么原因,说找不到文件。我用绝对路径是没有问题的。

Python 全系列/第二阶段:Python 深入与提高/GUI编程(隐藏) 28087楼

我之前安装nginx没有安装这个模块,现在按照这个:https://blog.csdn.net/wangjia55/article/details/91961569操作,老提示:bash: ./configure: 没有那个文件或目录。怎么解决啊?

image.png

image.png







JAVA 全系列/第十一阶段:分布式RPC调用和分布式文件存储/FastDFS 28090楼
JAVA 全系列/第一阶段:AI驱动的JAVA编程/控制语句、方法、递归算法 28092楼
JAVA 全系列/第二阶段:JAVA 基础深化和提高/多线程和并发编程(旧) 28093楼
JAVA 全系列/第十八阶段:亿级高并发电商项目_架构/编码(旧)/电商:使用Solr实现数据搜索 28095楼

课程分类

百战程序员微信公众号

百战程序员微信小程序

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