君子好逑 发表于 2020-5-20 14:39:07

抖音表白小程序

from tkinter import *
import tkinter.messagebox
import time
import pygame
import threading
import sys
from pygame.locals import *

def love():
    master = Toplevel()

    master.title("同道中人")
    screenWidth = master.winfo_screenwidth()
    screenHeight = master.winfo_screenheight()
    width = 600
    height = 500
    left = (screenWidth - width) / 2
    top = (screenHeight - height) / 2
    master.geometry("%dx%d+%d+%d" % (width, height, left, top))
    w = Label(master, image=lphoto)
    w.pack()
    Button(master,text='确定',command=master.quit).pack()

def dislove():
    master = Toplevel()

    master.title("让你认清自己!!!")
    screenWidth = master.winfo_screenwidth()
    screenHeight = master.winfo_screenheight()
    width = 600
    height = 380
    left = (screenWidth - width) / 2
    top = (screenHeight - height) / 2
    master.geometry("%dx%d+%d+%d" % (width, height, left, top))
    w = Label(master, image=disphoto)
    w.pack()
    Button(master,text='确定',command=master.destroy).pack()

def callbackClose():
    tkinter.messagebox.showwarning(title='警告', message='不许关闭,好好回答!!!')

def biaobai():
    pygame.mixer.init()
    pygame.mixer.music.load("D:\\KuGou\\任然 - 山外小楼夜听雨.mp3")
    pygame.mixer.music.set_volume(0.2)
    pygame.mixer.music.play(-1)
    bg_size = width,height = 200,190
    screen = pygame.display.set_mode(bg_size)
    pygame.display.set_caption('Music')
    clock = pygame.time.Clock()
    root = Tk()

    root.title("居中的窗口")
    screenWidth = root.winfo_screenwidth()# 获取显示区域的宽度
    screenHeight = root.winfo_screenheight()# 获取显示区域的高度
    width = 600# 设定窗口宽度
    height = 400# 设定窗口高度
    left = (screenWidth - width) / 2
    top = (screenHeight - height) / 2

    # 宽度x高度+x偏移+y偏移
    # 在设定宽度和高度的基础上指定窗口相对于屏幕左上角的偏移位置
    root.geometry("%dx%d+%d+%d" % (width, height, left, top))

    frame1 = Frame(root)
    frame2 = Frame(root)

    textlable = Label(frame1,text='祢豆子真漂亮')
    textlable.pack()

    global lphoto
    global disphoto
    lphoto = PhotoImage(file=r"E:\P.py\课堂练习.py\tkinter\喜欢.png")
    disphoto = PhotoImage(file=r"E:\P.py\课堂练习.py\tkinter\眼瞎.png")
    photo = PhotoImage(file=r"E:\P.py\课堂练习.py\tkinter\1.png")
    w = Label(frame1, image=photo)
    w.pack()

    Button(frame2,text='喜欢',command=love,width=15)\
      .grid(row=0,column=0,sticky=W,padx=50,pady=5)

    Button(frame2,text='不喜欢',command=dislove,width=15)\
      .grid(row=0,column=1,sticky=E,padx=50,pady=5)

    frame1.pack()
    frame2.pack()


    root.protocol("WM_DELETE_WINDOW", callbackClose)

    mainloop()

biaobai()

Twilight6 发表于 2020-5-21 08:37:13

!!!你应该发Python 的作品展示人才多,不然很少人看得见的~{:10_266:}

Twilight6 发表于 2020-5-21 08:39:36

晚上给你评分,评分还在CD中哈

而且其实你可以打包成exe文件,就可以不用python都可以运行了 ~

君子好逑 发表于 2020-5-22 14:20:56

Twilight6 发表于 2020-5-21 08:39
晚上给你评分,评分还在CD中哈

而且其实你可以打包成exe文件,就可以不用python都可以运行了 ~

用pyinstaller是吧,但是打包成的。exe文件太大了,而且图片什么的路径有点麻烦
页: [1]
查看完整版本: 抖音表白小程序