Formation icon indicating copy to clipboard operation
Formation copied to clipboard

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

Open sethstenzel opened this issue 2 years ago • 4 comments

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 avatar Jun 29 '23 20:06 sethstenzel

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 avatar Jun 29 '23 21:06 sethstenzel

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" />

sethstenzel avatar Jun 29 '23 22:06 sethstenzel

@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 avatar Jun 30 '23 08:06 ObaraEmmanuel

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.

ObaraEmmanuel avatar Jun 30 '23 09:06 ObaraEmmanuel