找回密码
 中文实名注册
查看: 372|回复: 2

吕泽-一键生成课程表

[复制链接]

702

主题

1094

帖子

2万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
22150
发表于 2023-3-11 19:27:51 | 显示全部楼层 |阅读模式
[Python] 纯文本查看 复制代码
from tkinter import *
from turtle import RawTurtle


def circ():
    tu.penup()
    tu.home()
    tu.clear()
    tu.speed(0)
    [x, y, R] = et1.get().split(',')
    try:
        x = int(x.replace('(', ''))
        y = int(y.replace(')', ''))
        R = int(R.strip())
    except:
        x, y, R = 0, 0, 50  # 输入错误则赋予默认值

    tu.goto(x, y-R)
    tu.pendown()
    tu.circle(R)


def rect():
    tu.penup()
    tu.home()
    tu.clear()
    tu.speed(0)
    tu.color('red', 'yellow')
    tu.begin_fill()
    [d, rad] = et2.get().split(',')
    try:
        d = int(d)
        rad = int(rad)
    except:
        d, rad = 200, 216  # 输入错误则赋予默认值
    tu.pendown()
    tu.back(d//5)
    while True:
        tu.forward(d)
        tu.left(rad)
        if abs(tu.pos()[0]+d//5) < 0.1 and abs(tu.pos()[1]) < 0.1:
            break
    tu.end_fill()


def taiji():
    tu.penup()
    tu.home()
    tu.clear()
    tu.speed(0)
    d = et3.get()
    try:
        d = int(d)
    except:
        d = 120  # 输入错误则赋予默认值
    tu.hideturtle()
    tu.goto(d//2, -d)
    tu.pendown()
    tu.begin_fill()
    tu.color('black', 'black')
    tu.circle(d, extent=180)
    tu.circle(d//2, extent=180)
    tu.circle(-d//2, extent=180)
    tu.end_fill()
    tu.circle(-d, extent=180)
    tu.penup()
    tu.goto(d//2, -d//6*4)
    tu.pendown()
    tu.begin_fill()
    tu.fillcolor("black")
    tu.circle(d//5, extent=360)
    tu.end_fill()
    tu.penup()
    tu.goto(d//2, d//3)
    tu.pendown()
    tu.begin_fill()
    tu.fillcolor("white")
    tu.circle(d//5, extent=360)
    tu.end_fill()
    tu.penup()


def main():
    global tu, et1, et2, et3
    root = Tk()
    root.geometry('520x520+150+300')
    root.title('turtle在tkinter.Canvas上的操作')
    root.resizable(False, False)
    canvas = Canvas(root, width=640, height=400)
    canvas.pack()

    tu = RawTurtle(canvas)
    tu.hideturtle()

    et1 = Entry(root, width=12)
    et1.place(x=30, y=480)
    et1.insert(0, '(50,-20), 100')
    bt1 = Button(root, text=' 画圆 ', command=circ)
    bt1.place(x=60, y=425)

    et2 = Entry(root, width=12)
    et2.place(x=190, y=480)
    et2.insert(0, '200, 216')
    bt2 = Button(root, text=' 多角星(或多边形) ', command=rect)
    bt2.place(x=180, y=425)

    et3 = Entry(root, width=12)
    et3.place(x=360, y=480)
    et3.insert(0, '120')
    bt3 = Button(root, text=' 太极 ', command=taiji)
    bt3.place(x=380, y=425)

    root.mainloop()


if __name__ == '__main__':

    main()

回复

使用道具 举报

702

主题

1094

帖子

2万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
22150
 楼主| 发表于 2023-3-11 19:31:48 | 显示全部楼层
[Python] 纯文本查看 复制代码
import turtle
import time
turtle.penup()
turtle.goto((-140*2), (-105*2))
turtle.pendown()
turtle.pencolor('red')
turtle.goto(140*2, (-105*2))
turtle.goto(140*2, 105*2)
turtle.goto((-140*2), 105*2)
turtle.goto((-140*2), (-105*2))
turtle.penup()
turtle.goto(125*2, (-90*2))
turtle.pendown()
turtle.goto(125*2, (-17.5*2))
turtle.goto((-90*2), (-17.5*2))
turtle.goto((-90*2), (-90*2))
turtle.goto(125*2, (-90*2))
turtle.penup()
turtle.goto((-90*2), 0.625*2)
turtle.pendown()
turtle.goto(125*2, 0.625*2)
turtle.goto(125*2, 55*2)
turtle.goto((-90*2), 55*2)
turtle.goto((-90*2), 0.625*2)
turtle.penup()
turtle.goto((-51*2), 55*2)
turtle.pendown()
turtle.goto((-51*2), 0.625*2)
turtle.goto((-7*2), 0.625*2)
turtle.goto((-7*2), 55*2)
turtle.goto(37*2, 55*2)
turtle.goto(37*2, 0.625*2)
turtle.goto(81*2, 0.625*2)
turtle.goto(81*2, 55*2)
turtle.goto(125*2, 55*2)
turtle.goto(125*2, 36.875*2)
turtle.goto((-90*2), 36.875*2)
turtle.goto((-90*2), 18.75*2)
turtle.goto(125*2, 18.75*2)
turtle.penup()
turtle.goto((-51*2), (-90*2))
turtle.pendown()
turtle.goto((-51*2), (-17.5*2))
turtle.goto((-7*2), (-17.5*2))
turtle.goto((-7*2), (-90*2))
turtle.goto(37*2, (-90*2))
turtle.goto(37*2, (-17.5*2))
turtle.goto(81*2, (-17.5*2))
turtle.goto(81*2, (-90*2))
turtle.penup()
turtle.goto((-90*2), (-35.625*2))
turtle.pendown()
turtle.goto(125*2, (-35.625*2))
turtle.goto(125*2, (-53.75*2))
turtle.goto((-90*2), (-53.75*2))
turtle.goto((-90*2), (-71.875*2))
turtle.goto(125*2, (-71.875*2))
turtle.penup()
turtle.goto((-24.1819*2), 65*2)
turtle.pendown()
turtle.write('课程表', font=('Arial', 20*2, 'normal'))
turtle.penup()
turtle.goto((-128*2), 26*2)
turtle.pendown()
turtle.write('上', font=('Arial', 20*2, 'normal'))
turtle.penup()
turtle.goto((-128*2), 0)
turtle.pendown()
turtle.write('午', font=('Arial', 20*2, 'normal'))
turtle.penup()
turtle.goto((-128*2), (-45*2))
turtle.pendown()
turtle.write('下', font=('Arial', 20*2, 'normal'))
turtle.penup()
turtle.goto((-128*2), (-45*3))
turtle.pendown()
turtle.write('午', font=('Arial', 20*2, 'normal'))
turtle.penup()

turtle.done()
回复

使用道具 举报

702

主题

1094

帖子

2万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
22150
 楼主| 发表于 2023-3-11 19:42:07 | 显示全部楼层
[Python] 纯文本查看 复制代码
from tkinter import *
from turtle import RawTurtle


def circ():
    tu.penup()
    tu.goto((-140*2), (-105*2))
    tu.pendown()
    tu.pencolor(et1.get())
    tu.goto(140*2, (-105*2))
    tu.goto(140*2, 105*2)
    tu.goto((-140*2), 105*2)
    tu.goto((-140*2), (-105*2))
    tu.penup()
    tu.goto(125*2, (-90*2))
    tu.pendown()
    tu.goto(125*2, (-17.5*2))
    tu.goto((-90*2), (-17.5*2))
    tu.goto((-90*2), (-90*2))
    tu.goto(125*2, (-90*2))
    tu.penup()
    tu.goto((-90*2), 0.625*2)
    tu.pendown()
    tu.goto(125*2, 0.625*2)
    tu.goto(125*2, 55*2)
    tu.goto((-90*2), 55*2)
    tu.goto((-90*2), 0.625*2)
    tu.penup()
    tu.goto((-51*2), 55*2)
    tu.pendown()
    tu.goto((-51*2), 0.625*2)
    tu.goto((-7*2), 0.625*2)
    tu.goto((-7*2), 55*2)
    tu.goto(37*2, 55*2)
    tu.goto(37*2, 0.625*2)
    tu.goto(81*2, 0.625*2)
    tu.goto(81*2, 55*2)
    tu.goto(125*2, 55*2)
    tu.goto(125*2, 36.875*2)
    tu.goto((-90*2), 36.875*2)
    tu.goto((-90*2), 18.75*2)
    tu.goto(125*2, 18.75*2)
    tu.penup()
    tu.goto((-51*2), (-90*2))
    tu.pendown()
    tu.goto((-51*2), (-17.5*2))
    tu.goto((-7*2), (-17.5*2))
    tu.goto((-7*2), (-90*2))
    tu.goto(37*2, (-90*2))
    tu.goto(37*2, (-17.5*2))
    tu.goto(81*2, (-17.5*2))
    tu.goto(81*2, (-90*2))
    tu.penup()
    tu.goto((-90*2), (-35.625*2))
    tu.pendown()
    tu.goto(125*2, (-35.625*2))
    tu.goto(125*2, (-53.75*2))
    tu.goto((-90*2), (-53.75*2))
    tu.goto((-90*2), (-71.875*2))
    tu.goto(125*2, (-71.875*2))
    tu.penup()
    tu.goto((-24.1819*2), 65*2)
    tu.pendown()
    tu.write('课程表', font=('Arial', 20*2, 'normal'))
    tu.penup()
    tu.goto((-128*2), 26*2)
    tu.pendown()
    tu.write('上', font=('Arial', 20*2, 'normal'))
    tu.penup()
    tu.goto((-128*2), 0)
    tu.pendown()
    tu.write('午', font=('Arial', 20*2, 'normal'))
    tu.penup()
    tu.goto((-128*2), (-45*2))
    tu.pendown()
    tu.write('下', font=('Arial', 20*2, 'normal'))
    tu.penup()
    tu.goto((-128*2), (-45*3))
    tu.pendown()
    tu.write('午', font=('Arial', 20*2, 'normal'))
    tu.penup()




def main():
    global tu, et1, et2, et3
    root = Tk()
    root.geometry('800x600+150+200')
    root.title('一键绘制课程表--吕泽')
    root.resizable(False, False)
    canvas = Canvas(root, width=800, height=600)
    canvas.pack()

    tu = RawTurtle(canvas)
    tu.hideturtle()

    et1 = Entry(root, width=8)
    et1.place(x=45, y=470)
    et1.insert(0, 'red')
    bt1 = Button(root, text=' 绘制 ', command=circ)
    bt1.place(x=60, y=420)

    bt2 = Button(root, text=' 打印 ',)
    bt2.place(x=60, y=520)
    '''
    et2 = Entry(root, width=12)
    et2.place(x=190, y=480)
    et2.insert(0, '200, 216')
    et3 = Entry(root, width=12)
    et3.place(x=360, y=480)
    et3.insert(0, '120')
    bt3 = Button(root, text=' 太极 ')
    bt3.place(x=380, y=425)
    '''
    root.mainloop()


if __name__ == '__main__':

    main()
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 中文实名注册

本版积分规则

小黑屋|东台市机器人学会 ( 苏ICP备2021035350号-1;苏ICP备2021035350号-2;苏ICP备2021035350号-3 )

GMT+8, 2024-11-21 20:25 , Processed in 0.040579 second(s), 28 queries .

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表