Python Forum
[Tkinter] Help with menu.
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tkinter] Help with menu.
#1
First of all I would like to say that I am new into python and even programming. There are many things that I have no idea how to do.

I would like to do some kind of menu where there is moving background (video) and images as buttons on it. I was able to make moving background. Buttons I am trying to put are visible but only somewere outside of background picture. I was also trying to use canvas but I have no idea how to put background video on it.

This is my code so far:
from tkinter import *
import tkinter as tk, threading
import imageio, random, os, winsound, cv2
from PIL import Image, ImageTk

img = cv2.imread("C:\\Users\\Rav\\Documents\\Projects\\Ppawel\\menu\\buttons1_nonactive.png")   #it works that way, not sure why
cv2.imwrite("C:\\Users\\Rav\\Documents\\Projects\\Ppawel\\menu\\buttons1_nonactive.png",img)

winsound.PlaySound(r"C:\\Users\\Rav\\Documents\\Projects\\Ppawel\\menu\\music1.wav", winsound.SND_ASYNC)    #music


option_list = [1,0]
x = random.choice(option_list)   #choose background video

if x == 1:
    video_name = "C:\\Users\\Rav\\Documents\\Projects\\project1\\menu\\0001-0100.mp4"  #This is video1 file path

if x == 0:
    video_name = "C:\\Users\\Rav\\Documents\\Projects\\project1\\menu\\0001-0408.mp4"  # This is video2 file path


video = imageio.get_reader(video_name)
def stream(label):

    var = 1
    while var == 1 :
        for image in video.iter_data():
            frame_image = ImageTk.PhotoImage(Image.fromarray(image))
            label.config(image=frame_image)
            label.image = frame_image

if __name__ == "__main__":

    root = tk.Tk()
    root.title("DSS")

    #########button_O1NA###################
    O1NA = Canvas( width=200, height=100)       #option 1 non-active
    O1NA.pack(expand=YES, fill=BOTH)
    O1NA_image = PhotoImage(file="C:\\Users\\Rav\\Documents\\Projects\\Ppawel\\menu\\buttons1_nonactive.png")
    O1NA.create_image(50, 10, image=O1NA_image, anchor=NW)

    my_label = tk.Label(root, compound='center', text='text')
    my_label.pack()
    thread = threading.Thread(target=stream, args=(my_label,))
    thread.daemon = 1
    thread.start()

    root.mainloop()
It looks like that:
[Image: dKbOIpW]

Dark button option is far away from background picture.
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020