tkinter, wm_state('zoomed') does not work on my app

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

tkinter, wm_state('zoomed') does not work on my app

问题

I'm running root.wm_state('zoomed') on my GUI app but it's just slightly moving my Window towards the bottom right.

我在我的GUI应用程序上运行root.wm_state('zoomed'),但它只是轻微地将我的窗口向右下方移动。

I have no clue why it's happening. Can anyone help?

我不知道为什么会发生这种情况。有人能帮忙吗?

Minimal reproducible example:

最小可重现示例:

import customtkinter as ctk

class MainApp(ctk.CTk):
        def __init__(self, *args, **kwargs):
            super().__init__(*args, **kwargs)
        
            self.title("Test Window")
            self.state('zoomed')

mapp = MainApp()
mapp.mainloop()
英文:

I'm running root.wm_state('zoomed') on my GUI app but it's just slightly moving my Window towards the bottom right.

I have no clue why it's happening. Can anyone help?

Minimal reproducible example:

import customtkinter as ctk

class MainApp(ctk.CTk):
        def __init__(self, *args, **kwargs):
            super().__init__(*args, **kwargs)
        
            self.title("Test Window")
            self.state('zoomed')

mapp = MainApp()
mapp.mainloop()

答案1

得分: 0

As customtkinter 覆盖了 .mainloop() 并在覆盖的 .mainloop() 中调用 .deiconify(),因此在 __init__() 中的 self.wm_state('zoomed') 的效果也被覆盖。

您可以通过将该行更改为 self.after(1, self.wm_state, 'zoomed') 来稍微延迟调用 self.wm_state('zoomed'),以便它在 .deiconify() 之后调用。

import customtkinter as ctk

class MainApp(ctk.CTk):
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.title("Test Window")
        self.after(1, self.wm_state, 'zoomed')

mapp = MainApp()
mapp.mainloop()

Note: The code portion is not translated, as requested.

英文:

As customtkinter overrides .mainloop() and call .deiconify() inside the override .mainloop() if it is Windows platform, so the effect of self.wm_state('zoomed') inside __init__() is override as well.

You can delay the calling of self.wm_state('zoomed') a bit by changing that line to self.after(1, self.wm_state, 'zoomed') so it is called after the .deiconify().

import customtkinter as ctk

class MainApp(ctk.CTk):
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.title("Test Window")
        self.after(1, self.wm_state, 'zoomed')

mapp = MainApp()
mapp.mainloop()

huangapple
  • 本文由 发表于 2023年5月18日 10:01:51
  • 转载请务必保留本文链接:https://go.coder-hub.com/76277272.html
匿名

发表评论

匿名网友

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

确定