会员可以在此提问,百战程序员老师有问必答
对大家有帮助的问答会被标记为“推荐”
看完课程过来浏览一下别人提的问题,会帮你学得更全面
截止目前,同学们一共提了 132365个问题
Python 全系列/第二阶段:Python 深入与提高/模块 1652楼
Python 全系列/第二阶段:Python 深入与提高/文件处理 1653楼
Python 全系列/第二阶段:Python 深入与提高/GUI编程(隐藏) 1654楼
Python 全系列/第二阶段:Python 深入与提高/GUI编程(隐藏) 1656楼
Python 全系列/第二阶段:Python 深入与提高/GUI编程(隐藏) 1657楼

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


from tkinter import *

from tkinter import messagebox


class Application(Frame):

    '''一个经典的GUI程序的类的写法'''


    def __init__(self,master=None):

        super().__init__(master)    #super()代表的是父类的定义,而不失父类的对象   super()是调用父类的方法,这里是调用父类初始化方法

        self.master=master

        self.pack()


        self.createWidget()


    def createWidget(self):

        '''创建组件'''

        self.btn01=Button(self)

        self.btn01['text']='点击送花'

        self.btn01.pack()   #调用布局管理器,把组建对象合理的放到窗口里

        self.btn01['command']=self.songhua   #command为调用函数


        #创建一个退出按钮

        self.btnQuit=Button(self,text='退出',command=root.destroy)      #destroy是结束窗口

        self.btnQuit.pack()


    def songhua(self):

        messagebox.showinfo('送花','送你99朵玫瑰花,亲亲我吧')


if __name__=='__main__':

    root=Tk()

    root.geometry('400x100+200+300')

    root.title('一个经典的GUI程序的类的测试')

    app=Application(master=root)

    root.mainloop()    #调用组件的mainloop方法,进入事件循环,展示效果



'''

老师您好,以下遇到几个问题:

1.self.btn01=Button(self)和self.btnQuit=Button(self,text='退出',command=root.destroy) 为什么只把self传进去里面呢,看得不是很懂?

2.from tkinter import messagebox  在tkinter中导入的这个messagebox这个是啥玩意呢?

3.if __name__=='__main__':  这个测试代码不是只有在程序脚本直接运行的时候才会有效的吗,怎么在模块导入的情况下也可以正常执行?

4.app=Application(master=root) 为什么要在前面赋值给app,不加可以嘛?

5.self.master=master  这一行我注释掉程序也一样可以正常执行,这是为什么呢?


'''


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

老师 ,我照着高淇老师上传的模块显示,上传失败是怎么回事

1、Microsoft Windows [版本 10.0.18363.1379]
(c) 2019 Microsoft Corporation。保留所有权利。

(mypro-modules) C:\Users\lzh\Desktop\资料\mypro-modules\math3>python setup.py sdist upload
running sdist
running check
warning: check: missing required meta-data: url

warning: sdist: manifest template 'MANIFEST.in' does not exist (using default file list)

warning: sdist: standard file not found: should have one of README, README.txt, README.rst

writing manifest file 'MANIFEST'
creating baizhanSuperMath-1.0
creating baizhanSuperMath-1.0\baizhanSuperMath
making hard links in baizhanSuperMath-1.0...
hard linking setup.py -> baizhanSuperMath-1.0
hard linking baizhanSuperMath\__init__.py -> baizhanSuperMath-1.0\baizhanSuperMath
hard linking baizhanSuperMath\demo1.py -> baizhanSuperMath-1.0\baizhanSuperMath
hard linking baizhanSuperMath\demo2.py -> baizhanSuperMath-1.0\baizhanSuperMath
Creating tar archive
removing 'baizhanSuperMath-1.0' (and everything under it)
running upload
Submitting dist\baizhanSuperMath-1.0.tar.gz to https://upload.pypi.org/legacy/
Upload failed (400): Invalid value for blake2_256_digest. Error: Use a valid, hex-encoded, BLAKE2 message digest.
error: Upload failed (400): Invalid value for blake2_256_digest. Error: Use a valid, hex-encoded, BLAKE2 message digest.

(mypro-modules) C:\Users\lzh\Desktop\资料\mypro-modules\math3>

就显示失败 什么原因啊

image.png

Python 全系列/第二阶段:Python 深入与提高/模块 1660楼
Python 全系列/第二阶段:Python 深入与提高/GUI编程(隐藏) 1661楼
Python 全系列/第二阶段:Python 深入与提高/GUI编程(隐藏) 1662楼
Python 全系列/第二阶段:Python 深入与提高/文件处理 1663楼

课程分类

百战程序员微信公众号

百战程序员微信小程序

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