Setting a tkinter window to be fullscreen using "-fullscreen" attribute after changing resolution with ctypes does not resize the window correctly

huangapple go评论94阅读模式
英文:

Setting a tkinter window to be fullscreen using "-fullscreen" attribute after changing resolution with ctypes does not resize the window correctly

问题

我有一个使用ctypes缩放过的tkinter窗口。当我尝试使用"-fullscreen"属性使窗口全屏时,窗口不会调整大小以覆盖整个屏幕,而只会覆盖屏幕的一半。

示例:

  1. import tkinter as tk
  2. import ctypes
  3. window = tk.Tk()
  4. window.tk.call('tk', 'scaling', 2) ## 将窗口的缩放比例加倍
  5. ctypes.windll.shcore.SetProcessDpiAwareness(2) ## 将窗口的分辨率加倍
  6. ## 窗口现在有双倍分辨率和1倍缩放比例
  7. window.attributes("-fullscreen", True) ## 将窗口设置为全屏模式不正常工作
  8. window.mainloop()

此外,我不知道这是否与winfo_screenwidth/height有关,但它返回了不正确的屏幕宽度和高度值。

感谢任何帮助。

英文:

I have a tkinter window that has been scaled using ctypes. When I try to make the window full-screen using the "-fullscreen" attribute, the window does not resize to cover the screen and instead, only covers half the screen.

Example:

  1. import tkinter as tk
  2. import ctypes
  3. window = tk.Tk()
  4. window.tk.call('tk', 'scaling', 2) ## Double the scale of the window
  5. ctypes.windll.shcore.SetProcessDpiAwareness(2) ## Double the resolution of the window
  6. ## Window now has double resolution with 1x scale
  7. window.attributes("-fullscreen", True) ## Making window full-screen doesn't work properly
  8. window.mainloop()

Also, I don't know if this is related, but winfo_screenwidth/height returns an incorrect value for the screen width and height.

Thanks for any help.

答案1

得分: 0

用以下内容替换:

  1. window.attributes("-fullscreen", True)

为:

  1. window.geometry(f"{window.winfo_vrootwidth()}x{window.winfo_screenheight()}+{-7}+0")

你这么做了吗?

英文:

How about replacing

  1. window.attributes("-fullscreen", True)

with

  1. window.geometry(f"{window.winfo_vrootwidth()}x{window.winfo_screenheight()}+{-7}+0")

did you?

huangapple
  • 本文由 发表于 2023年2月6日 09:56:08
  • 转载请务必保留本文链接:https://go.coder-hub.com/75356744.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定