会员可以在此提问,百战程序员老师有问必答
对大家有帮助的问答会被标记为“推荐”
看完课程过来浏览一下别人提的问题,会帮你学得更全面
截止目前,同学们一共提了 133326个问题
大数据全系列/第二阶段:大型网站高并发处理/大型网站高并发处理 24031楼

用Python绘制一个棋盘18*18我不会做 用更简洁的方法,思路想不明白,我自己想的代码。原始方法 找到坐标 再利用x轴与y轴之间的对称找到对称坐标 去到那个坐标就化成一条先。在一条一条画。

我的 代码:


import turtle
turtle.pen()

turtle.speed(0)

turtle.penup()
turtle.goto(160,-200)
turtle.pendown()
turtle.goto(-200,-200)

turtle.penup()
turtle.goto(160,-180)
turtle.pendown()
turtle.goto(-200,-180)

turtle.penup()
turtle.goto(160,-160)
turtle.pendown()
turtle.goto(-200,-160)

turtle.penup()
turtle.goto(160,-140)
turtle.pendown()
turtle.goto(-200,-140)

turtle.penup()
turtle.goto(160,-120)
turtle.pendown()
turtle.goto(-200,-120)

turtle.penup()
turtle.goto(160,-100)
turtle.pendown()
turtle.goto(-200,-100)

turtle.penup()
turtle.goto(160,-80)
turtle.pendown()
turtle.goto(-200,-80)

turtle.penup()
turtle.goto(160,-60)
turtle.pendown()
turtle.goto(-200,-60)

turtle.penup()
turtle.goto(160,-40)
turtle.pendown()
turtle.goto(-200,-40)

turtle.penup()
turtle.goto(160,-20)
turtle.pendown()
turtle.goto(-200,-20)

turtle.penup()
turtle.goto(160,0)
turtle.pendown()
turtle.goto(-200,0)

turtle.penup()
turtle.goto(160,20)
turtle.pendown()
turtle.goto(-200,20)

turtle.penup()
turtle.goto(160,40)
turtle.pendown()
turtle.goto(-200,40)

turtle.penup()
turtle.goto(160,60)
turtle.pendown()
turtle.goto(-200,60)

turtle.penup()
turtle.goto(160,80)
turtle.pendown()
turtle.goto(-200,80)

turtle.penup()
turtle.goto(160,100)
turtle.pendown()
turtle.goto(-200,100)

turtle.penup()
turtle.goto(160,120)
turtle.pendown()
turtle.goto(-200,120)

turtle.penup()
turtle.goto(160,140)
turtle.pendown()
turtle.goto(-200,140)

turtle.penup()
turtle.goto(160,160)
turtle.pendown()
turtle.goto(-200,160)

turtle.penup()
turtle.goto(-200,160)
turtle.pendown()
turtle.goto(-200,-200)

turtle.penup()
turtle.goto(-180,160)
turtle.pendown()
turtle.goto(-180,-200)

turtle.penup()
turtle.goto(-160,160)
turtle.pendown()
turtle.goto(-160,-200)

turtle.penup()
turtle.goto(-140,160)
turtle.pendown()
turtle.goto(-140,-200)

turtle.penup()
turtle.goto(-120,160)
turtle.pendown()
turtle.goto(-120,-200)

turtle.penup()
turtle.goto(-100,160)
turtle.pendown()
turtle.goto(-100,-200)

turtle.penup()
turtle.goto(-80,160)
turtle.pendown()
turtle.goto(-80,-200)

turtle.penup()
turtle.goto(-60,160)
turtle.pendown()
turtle.goto(-60,-200)

turtle.penup()
turtle.goto(-40,160)
turtle.pendown()
turtle.goto(-40,-200)

turtle.penup()
turtle.goto(-20,160)
turtle.pendown()
turtle.goto(-20,-200)

turtle.penup()
turtle.goto(0,160)
turtle.pendown()
turtle.goto(0,-200)

turtle.penup()
turtle.goto(20,160)
turtle.pendown()
turtle.goto(20,-200)

turtle.penup()
turtle.goto(40,160)
turtle.pendown()
turtle.goto(40,-200)

turtle.penup()
turtle.goto(60,160)
turtle.pendown()
turtle.goto(60,-200)

turtle.penup()
turtle.goto(80,160)
turtle.pendown()
turtle.goto(80,-200)

turtle.penup()
turtle.goto(100,160)
turtle.pendown()
turtle.goto(100,-200)

turtle.penup()
turtle.goto(120,160)
turtle.pendown()
turtle.goto(120,-200)

turtle.penup()
turtle.goto(140,160)
turtle.pendown()
turtle.goto(140,-200)

turtle.penup()
turtle.goto(160,160)
turtle.pendown()
turtle.goto(160,-200)

turtle.done()

好长 有没有更好方法 而且要解释 能明白

Python 全系列/第一阶段:Python入门/控制语句 24032楼
Python 全系列/第三阶段:Python 网络与并发编程/网络通信 24033楼
人工智能/第七阶段:机器学习-无监督学习(旧)/EM算法和GMM高斯混合模型 24036楼
JAVA 全系列/第二十九阶段:高并发实战和BATJ大厂面试重难点/Java并发编程核心 24037楼

'''测试一个经典的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编程(隐藏) 24038楼

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

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 深入与提高/模块 24039楼
Python 全系列/第二阶段:Python 深入与提高/GUI编程(隐藏) 24040楼
JAVA 全系列/第一阶段:AI驱动的JAVA编程/变量、数据类型、运算符 24041楼
Python 全系列/第二阶段:Python 深入与提高/GUI编程(隐藏) 24042楼
JAVA 全系列/第十阶段:权限控制与安全认证/Spring Security(旧) 24043楼
Python 全系列/第二阶段:Python 深入与提高/文件处理 24044楼

课程分类

百战程序员微信公众号

百战程序员微信小程序

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