【发布时间】:2020-02-15 16:43:50
【问题描述】:
这似乎是一个愚蠢的问题,但在 stackoverflow 上找不到答案,我需要这个项目。希望有人能帮忙。
现在,我正在创建跨平台 screen recorder。我在下面附上了当前的用户界面。在下面的 UI 中,如果再次按下,我希望暂停按钮变为播放按钮(交换图像),反之亦然。我在这里附上整个 GUI 代码。请帮我解决这个问题。我在 Ubuntu 操作系统上使用 python 3.7,但它应该适用于所有平台。
除此之外,我还想知道如何为整个窗口设置背景,我尝试了画布但似乎没有用。我还想在显示“屏幕摄像师”的标签旁边放置一个徽标,如果可以的话,我可以知道如何对齐它。
下面是代码:-
from tkinter import *
from tkinter.ttk import *
from detect_screen_size import detect_screen_size
from PIL import Image, ImageTk
import tkinter as tk
paused= True
LOGO_PNG_PATH="pic/logo.png"
LOGO_PATH="pic/logo.ico"
BG_PATH = 'pic/bg_1.jpg'
LOGO_LINUX_PATH="@pic/logo_1.xbm"
def play():
global paused,image2
print("start of function",paused)
if paused:
image2=PhotoImage(file="/media/admin_ash/New Volume/proj/screen rec/pic/gui_controls/play.png")
paused=False
print("inside if function",paused)
else:
image2 = PhotoImage(file="/media/admin_ash/New Volume/proj/screen rec/pic/gui_controls/symbol.png")
paused=True
print("inside if function", paused)
def pause():
print("button hit")
def stop():
print("button stop")
def record():
print("button rec")
WIDTH, HEIGHT = 350, 100
root = Tk()
#root.geometry('{}x{}'.format(WIDTH, HEIGHT))
root.resizable(0, 0)
root.style = Style()
#('winnative', 'clam', 'alt', 'default', 'classic', 'vista', 'xpnative')
root.style.theme_use("clam")
if detect_screen_size().detect_os()=="Linux":
root.iconbitmap(LOGO_LINUX_PATH)
else:
root.iconbitmap(default=LOGO_PATH)
root.title("Screenvideographer")
frame_display = tk.Frame(relief=FLAT)
label = tk.Label(master=frame_display, text="Screen Videographer")
label.pack()
canvas = Canvas(root, width = 50, height = 50)
canvas.pack(side=LEFT)
img = PhotoImage(file=LOGO_PNG_PATH)
canvas.create_image(50,50, anchor=NW, image=img)
frame_display.pack()
frame_controls = tk.Frame(relief=FLAT)
image1=PhotoImage(file="/media/admin_ash/New Volume/proj/screen rec/pic/gui_controls/record.png")
image2=PhotoImage(file="/media/admin_ash/New Volume/proj/screen rec/pic/gui_controls/symbol.png")
image3=PhotoImage(file="/media/admin_ash/New Volume/proj/screen rec/pic/gui_controls/stop.png")
Button(master=frame_controls,width=35,image=image1,command=record).pack(side=LEFT,padx=7,pady=4)
Button(master=frame_controls,width=35,image=image2,command=play).pack(side=LEFT,padx=7,pady=4)
Button(master=frame_controls,width=35,image=image3,command=stop).pack(side=RIGHT,padx=7,pady=4)
frame_controls.pack()
root.mainloop()
谢谢!!
【问题讨论】:
标签: python-3.x tkinter imagebutton