【问题标题】:Make tkinter GUI window on top over omxplayer HDMI video screen在 omxplayer HDMI 视频屏幕上方制作 tkinter GUI 窗口
【发布时间】:2019-04-16 12:54:14
【问题描述】:

我有一个物联网项目,我在树莓派零上使用python-3.6,在 GUI 上使用tkinter。

Pi 始终通过直接 HDMI (omxplayer) 在电视上播放视频。

问题: 我需要打开一个tkinter GUI 窗口来连接wifi,但GUI 显示索引低于omxplayer 屏幕。

我想要什么 我想在 omxplayer 屏幕上方显示 GUI 以连接 wi-fi。

我试过了:

1 root.wm_attributes("-topmost", 1) 
  #Not working wm is not defined

2 root.overridedirect(1)
  root.wm_attributes("-topmost", 1)
  #Window is jumping on top of every other applications but not over omxplayer.

3 root.attributes("-topmost", 1)
  #Window is jumping on top of every other applications but not over omxplayer.

4 root.lift()
  #Not working

【问题讨论】:

    标签: python tkinter omxplayer


    【解决方案1】:

    我得到了一个解决方案,虽然它不是一个有效的解决方案。

    我做了什么?

    我没有在顶部设置tkinter GUI,而是绑定热键ctrl+j 以隐藏omxplayer 屏幕和ctrl+k 以显示屏幕。

    from omxplayer.player import OMXPlayer
    import omxplayer.keys
    import codecs
    from pynput import keyboard
    import threading
    
    xpress = False
    
    # The key combination to check
    COMBINATIONS = [
        {keyboard.Key.ctrl, keyboard.KeyCode(char='j')},
        {keyboard.Key.ctrl, keyboard.KeyCode(char='J')},
        {keyboard.Key.ctrl, keyboard.KeyCode(char='k')},
        {keyboard.Key.ctrl, keyboard.KeyCode(char='K')}
    ]
    
    # The currently active modifiers
    current = set()
    
    def execute(key):
        keys = str(key).replace("'", "")
        print ("Do Something", keys)
    
        if keys == 'j':
            global xpress
            xpress = True
            print(xpress)
        else:
            xpress = False
            print(xpress)
    
    def on_press(key):
        if any([key in COMBO for COMBO in COMBINATIONS]):
            current.add(key)
            if any(all(k in current for k in COMBO) for COMBO in COMBINATIONS):
                execute(key)
    
    def on_release(key):
        if any([key in COMBO for COMBO in COMBINATIONS]):
            current.remove(key)
    
    def ThKeyboad():
        with keyboard.Listener(on_press=on_press, on_release=on_release) as listener:
            listener.join()
    
    
    t1 = threading.Thread(target=ThKeyboad, args=[])
    t1.start()
    
    #OMXPlayer Code
    
    player = OMXPlayer('/home/pi/outhum/video/default.mp4', dbus_name='org.mpris.MediaPlayer2.omxplayer2')
    
    if xpress:
        player.hide_video()
    else:
        player.show_video()
    a = player.duration()
    time.sleep(a)
    player.quit()
    
    

    【讨论】:

    • 请注意,播放器将隐藏在下一个 omxplayer 实例上,同样用于取消隐藏。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-03
    • 1970-01-01
    • 2011-03-22
    • 1970-01-01
    • 1970-01-01
    • 2020-01-29
    相关资源
    最近更新 更多