ziheng -学习按钮制作

import tkinter as tk

window = tk.Tk()
window.geometry("600x700")
window.title("xxx")


def people():
    la["text"] = "我点"





def jie():
    import pygame as p
    import time

    p.init()
    screen = p.display.set_mode((682, 500))
    # 设置标题 captiion 船长 首都 ----标题
    p.display.set_caption("无限接球")
    # 具体指应用函数的时候写括号
    ballx = 100
    bally = 150
    ban_x, ban_y, ban_k, ban_g = 300, 460, 120, 40
    # 让电脑没过多少毫秒监控一次
    p.key.set_repeat(100, 1)
    # 1.设置字体 font 字体
    ziti = p.font.Font(None, 30)
    score = 0
    while 1 > 0:
        for sj in p.event.get():
            # print(sj)
            if sj.type == p.QUIT:
                p.quit()
            # 判断事件类型是不是按键 键 key
            elif sj.type == p.KEYDOWN:
                # 判断按了哪一个键
                if sj.key == p.K_RIGHT:
                    ban_x = ban_x + 10
                elif sj.key == p.K_LEFT:
                    ban_x = ban_x - 10
            # 判断事件类型是不是鼠标动作 motion动作
            elif sj.type == p.MOUSEMOTION:
                ban_x, _ = sj.pos
        screen.fill((120, 255, 30))
        bally = bally + 1
        if bally > 500:
            bally = 0
            ballx = ballx + 100
        if ballx > 682:
            ballx = 0
        # 左边空气墙
        if ban_x < -50:
            ban_x = 5
        elif 682 < ban_x:
            ban_x = 580

        # 画一个小球
        p.draw.circle(screen, (172, 85, 255), (ballx, bally), 10, 0)
        # 画一个长方形  rect 屏幕 颜色
        p.draw.rect(screen, (172, 85, 255), (ban_x, ban_y, ban_k, ban_g), 0)

        score = score + 1
        # 设置文字
        text = ziti.render("score:%d" % score, True, (0, 0, 0))
        screen.blit(text, (132, 436))

        p.display.update()
        # time.sleep(0.00001)



la = tk.Label(
    window,
    font=(None, 30),
    text="点赞人数",
    bg="#B0E0E6",
    fg="red",
    width=10,
    height=3,
)

la.pack()

# 按钮 Button
btn = tk.Button(
    window,
    font=(None, 20),
    text="点赞",
    bg="#54FF9F",
    fg="#000000",
    command=people, # command 命令,后面接的函数名
)
btn.pack()





bth = tk.Button(
    window,
    font = (None,20),
    text = "揭小球游戏",
    bg = "#54FF0A",
    fg = "#010101",
    command = jie,
)
bth.pack()

def duo():
    # 给一个圆形填充蓝色  circle
    import turtle as t

    # 画脸
    def face():
        """画脸"""
        # t.shape("turtle")
        t.color("black")
        t.fillcolor("blue")
        t.begin_fill()
        t.circle(150)
        t.end_fill()
        t.fillcolor("white")
        t.begin_fill()
        t.circle(120)
        t.end_fill()

    def eye():
        # 左边眼睛
        # 抬笔
        t.up()
        t.left(90)
        t.fd(240)
        t.down()
        t.fillcolor("white")
        t.begin_fill()
        t.circle(30)
        t.end_fill()
        # 点 dot
        # 抬笔
        t.up()
        t.left(90)
        t.fd(16)
        t.down()
        t.dot(20)
        t.up()
        t.right(180)
        t.fd(20)
        t.down()
        # 右边眼睛
        t.up()
        t.right(90)
        t.down()
        t.fillcolor("white")
        t.begin_fill()
        t.circle(30)
        t.end_fill()
        # 点 dot
        # 抬笔
        t.up()
        t.left(90)
        t.fd(16)
        t.down()
        t.dot(20)
        t.up()
        t.right(180)
        t.fd(28)
        t.down()

    def nose():
        t.up()
        t.goto(0, 220)
        t.down()
        t.fillcolor("red")
        t.begin_fill()
        t.circle(18)
        t.end_fill()

    def mouth():
        t.up()
        t.goto(0, 184)
        t.down()
        t.left(90)
        t.fd(130)
        t.left(90)
        t.circle(110, 40)

    t.speed(0)
    face()
    eye()
    nose()
    mouth()
    t.done()


a = tk.Button(
    window,
    font = (None,20),
    text = "多啦A梦",
    bg = "#63FF0b",
    fg = "#324242",
    command = duo,
)
a.pack()



window.mainloop()
import tkinter as tk

window = tk.Tk()
window.geometry("1440x960")
window.title("xxx")
la = tk.Label(
    window,
    font=(None, 100),
    text="你的电脑\n中毒了\n你的电脑\n中毒了",
    bg="black",
    fg="green",
    width=400,
    height=300,
)

la.pack()

window.mainloop()
发布了516 篇原创文章 · 获赞 21 · 访问量 2万+

猜你喜欢

转载自blog.csdn.net/houlaos/article/details/105064821