简体   繁体   English

如何在任何计算机的右上角找到tkinter窗口?

[英]how can I get a tkinter window in the top right corner of any computer?

I've tried using the screen size and window size methods but as they don't give numerical values I cant subtract them from one another. 我尝试使用屏幕大小和窗口大小方法,但是由于它们不提供数值,因此我无法将它们彼此相减。 Here's my code: 这是我的代码:

from tkinter import *
statistics = Tk()
screenwidth = statistics.winfo_screenwidth
windowwidth = statistics.winfo_width
distance = screenwidth - windowwidth
statistics.geometry(+distance+'0')

winfo_screenwidth and winfo_width are both functions, so you need to call them rather than reference them. winfo_screenwidthwinfo_width都是函数,因此您需要调用它们而不是引用它们。 So, to get these values you should do it like this: 因此,要获得这些值,您应该这样做:

screenwidth = statistics.winfo_screenwidth()
windowwidth = statistics.winfo_width()

Be aware that until the window actually appears on screen, it's width and height will be 1. 请注意,在窗口实际出现在屏幕上之前,其宽度和高度将为1。

Depending on the platform you're running on, you don't need to do any of those calculations. 根据您所运行的平台,您不需要执行任何这些计算。 If you give negative values for the geometry, it will refer to the location of the bottom right corner of the window with respect to the bottom right edge of the screen. 如果为几何提供负值,则它将引用窗口右下角相对于屏幕右下角的位置。 Positive and negative numbers can be mixed, so "-1+1" means to put the app in the upper-right corner. 可以混合使用正数和负数,因此“ -1 + 1”表示将应用放在右上角。

This doesn't seem to hold true for OSX, FWIW. 对于OSX,FWIW,似乎并非如此。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM