简体   繁体   中英

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. 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.

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.

This doesn't seem to hold true for OSX, FWIW.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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