python-tkinter:简单GUI界面-背景图+文字
参考:
https://b23.tv/hTUScB
import tkinter
import tkinter.messagebox
from PIL import Image, ImageTk
import numpy as np
import os
os.system('1.mp3')
'''
import pygame
import time
#playsound.playsound('1.mp3')
#screen = pygame.display.set_mode([200,100])
pygame.mixer.init()
pygame.mixer.music.load('2.mp3')
if not pygame.mixer.music.get_busy():
pygame.mixer.music.play()
#time.sleep(10)
'''
boy_said=["我爱你","我喜欢你","额の…你为什么不说话","你是猪","xx","怎么样","我好喜欢你","可恶的家伙","嗯,是的","xx","你快快变猪","你喜欢我吗","睡觉"]
girl_said=["你是猪","那不是你变猪的理由","我要睡觉","...","嗯","就像胸口碎大石一样","你该减肥了","赶紧睡觉吧你,你今天是不是睡太多兴奋过度了","那明天得叫你早起","小鸡啄米","你才变猪","喜欢","晚安"]
l=len(boy_said)
i=0
root_window = tkinter.Tk()
root_window.title('日常悄悄话')
image_file = Image.open("1.jpg")
photo = ImageTk.PhotoImage(image_file)
fwagui=tkinter.Frame(root_window,padx=2,pady=2)
fwagui.grid(row=0,column=0)
tkinter.Label(fwagui,image=photo).grid(row = 0, column = 0,rowspan=3,columnspan=3)
boy_var=tkinter.StringVar()
boy_msg = tkinter.Message(fwagui,textvariable=boy_var,relief=tkinter.RAISED,width=55)
boy_var.set(boy_said[i])
boy_msg.grid(row=0,column=0)
girl_var=tkinter.StringVar()
girl_msg = tkinter.Message(fwagui,textvariable=girl_var,relief=tkinter.RAISED,width=55)
girl_var.set(girl_said[i])
girl_msg.grid(row=0,column=2)
def predicty():
global i
i=i+1
if i<l:
boy_var.set(boy_said[i])
girl_var.set(girl_said[i])
else:
next_button.grid_forget()
next_button = tkinter.Button(fwagui, text ="下", command = predicty,bg="#000000",width=3)
next_button.grid(row=1,column=1)
'''
def playm():
pygame.mixer.music.play()
play_button = tkinter.Button(fwagui, text ="播放", command = playm,width=1)
play_button.grid(row=0,column=3)
def pausem():
pygame.mixer.music.pause()
pause_button = tkinter.Button(fwagui, text ="暂停", command = pausem,width=1)
pause_button.grid(row=1,column=3)
def stopm():
pygame.mixer.music.stop()
stop_button = tkinter.Button(fwagui, text ="停止", command = stopm,width=1)
stop_button.grid(row=2,column=3)
'''
root_window.mainloop()