Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Application spawning parent tk window even though layout has a top level. #21

Closed
sethstenzel opened this issue Jun 29, 2023 · 4 comments
Labels
bug Something isn't working

Comments

@sethstenzel
Copy link

When running the application, a smaller tk parent window is created.

Steps to reproduce the behavior:

  1. Start new project
  2. Save the layout
  3. Run app loading layout
  4. See the error

It is not using the parent object, which is set, but instead spawning a new tk parent and shouldn't be.
Example Image

  • OS: Windows
  • formation Version 0.6.1
  • Python version: 3.11.0
  • tk version: 8.6

app.py

from formation import AppBuilder

app = AppBuilder(path="test.xml")
app.mainloop()

test.xml

<?xml version='1.0' encoding='utf-8'?>
<tkinter.Toplevel xmlns:attr="http://www.hoversetformationstudio.com/styles/" xmlns:layout="http://www.hoversetformationstudio.com/layouts/" name="toplevel_1" attr:layout="place" layout:width="1170" layout:height="858" layout:x="30" layout:y="30"><meth name="title"><arg value="title" /></meth><meth name="geometry"><arg value="1170x825+0+0" /></meth><meta major="6" minor="1" name="version" /></tkinter.Toplevel>
@sethstenzel sethstenzel added the bug Something isn't working label Jun 29, 2023
@sethstenzel
Copy link
Author

I noticed the last PR states there are fixes to top level.
I tried installing both for PyPI and directly from GH, but the issue seems present for me in both.

@sethstenzel
Copy link
Author

sethstenzel commented Jun 29, 2023

For the time being, just grabby the child Destroy and killing the app after a withdraw on the root. Probably not the best way to do this.

from formation import AppBuilder
import tkinter as tk
import sys

# TODO Remove this one the bug is fixed in the library
def kill_app(*args):
    sys.exit()

root = tk.Tk()
root.withdraw()

app = AppBuilder(app=root, path="layout.xml")
app.connect_callbacks(globals())
app.mainloop()

and <event sequence="&lt;Destroy&gt;" handler="kill_app" add="True" />

@ObaraEmmanuel
Copy link
Owner

ObaraEmmanuel commented Jun 30, 2023

@seth-c-stenzel Normally if you use Toplevel as your root widget tkinter spawns a Tk widget to act as the default root. To solve this make sure your root widget is a Tk object not a Toplevel. Your test.xml should be

<?xml version='1.0' encoding='utf-8'?>
<tkinter.Tk xmlns:attr="http://www.hoversetformationstudio.com/styles/" xmlns:layout="http://www.hoversetformationstudio.com/layouts/" name="toplevel_1" attr:layout="place" layout:width="1170" layout:height="858" layout:x="30" layout:y="30"><meth name="title"><arg value="title" /></meth><meth name="geometry"><arg value="1170x825+0+0" /></meth><meta major="6" minor="1" name="version" /></tkinter.Tk>

@ObaraEmmanuel
Copy link
Owner

In the designer, you can delete your root widget which is probably a Toplevel object and then instead drag a Tk object to the designer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants