Tkinter,透明背景,Linux

时间:2018-02-17 04:38:23

标签: python linux tkinter

有没有办法在Linux上的Tkinter窗口中获得透明背景?

我目前看到的唯一方法是:

import tkinter as tk

root = tk.Tk()

root.overrideredirect(True)
root.wait_visibility(True)
root.wm_attributes("-alpha", 0.0)

canvas = tk.Canvas(root, width=300, height=300)
canvas.pack()
canvas.create_rectangle(50, 25, 150, 75, fill="red")

root.mainloop()

但是,这不是我想要的。我想让背景变得透明,所以我的叠加可能是其他东西。

我在这里发现了一些帖子,但它们只涵盖Windows和Mac OS上的bg透明度。 Linux相关的只是alpha?

linux mint tkinter transparent window

transparent background in a tkinter window

3 个答案:

答案 0 :(得分:1)

我很确定这会奏效。

root.wm_attributes("-alpha", 0.5)
root.wait_visibility(root)

答案 1 :(得分:0)

添加以下行:

interface keyMap {
  name: string;
  mark: number;
}

let keyMapInstance: keyMap = { name: 'John', mark: 85 }

interface development extends keyMap {
  (code: string): void
}

this answer.中提到的“root.wm_attributes ..”行之前的

它适用于Ubuntu 16.04

答案 2 :(得分:0)

它在 Ubuntu 20.04、Linux Mint 20.1、Cinnamon 上对我有用
Python 3.6

import tkinter as tk
root = tk.Tk()
root.overrideredirect(True)
root.wait_visibility(root)
root.wm_attributes("-alpha", 0.5)
root.mainloop()
相关问题