You can use the win32api
's .GetMonitorInfo()
to find the 'working area' of the monitor, which is the area of the monitor without the taskbar. Then, seeing where the taskbar is, you can place the window in a corner of the working area. See this example:
import win32api
import Tkinter as tk
for monitor in win32api.EnumDisplayMonitors():
monitor_info = win32api.GetMonitorInfo(monitor[0])
if monitor_info['Flags'] == 1:
break
work_area = monitor_info['Work']
total_area = monitor_info['Monitor']
width = 300
height = 200
side = [i for i in range(4) if work_area[i]!=total_area[i]]
# Left
if side ==[0]:
x = str(work_area[0])
y = str(work_area[3]-height)
# Top
elif side == [1]:
x = str(work_area[2]-width)
y = str(work_area[1])
# Right
elif side == [2]:
x = str(work_area[2]-width)
y = str(work_area[3]-height)
# Bottom
elif side == [3]:
x = str(work_area[2]-width)
y = str(work_area[3]-height)
else:
x = str(work_area[2]-width)
y = str(work_area[3]-height)
geom = '{}x{}+{}+{}'.format(width, height, x, y)
root = tk.Tk()
root.configure(background='red')
root.geometry(geom)
root.overrideredirect(True)
root.mainloop()
Note that I've used overrideredirect
to get rid of the frame of the window, since this messes with the placing a bit.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…