alejandroautalan / pygubu-designer

A simple GUI designer for the python tkinter module
GNU General Public License v3.0
838 stars 102 forks source link

CustomTk two windows open #188

Closed Sgambe33 closed 1 year ago

Sgambe33 commented 1 year ago

Hi, I installed the CustomTk support and created a GUI. I then proceded to export it as a .ui file and copy/pasted the generated code into a .py file. I don't know if this is normal but when I start the file two windows are opened: one represents my GUI with all the widgets, the second one is an empty default Tkinter window. Is there a way to remove the empty one?

alejandroautalan commented 1 year ago

Hello @Sgambe33, thanks for trying pygubu.

What is your toplevel widget? Customtkinter recommends to use the Ctk class as your main widget. So your app tree widget should look like this:

2023-01-25_21-46

For extra windows and dialogs you should use a CtkToplevel.

If you have another scenario, please add an example code so I can analyze it.

Regards Alejandro A.

example.ui

<?xml version='1.0' encoding='utf-8'?>
<interface version="1.3">
  <object class="customtkinter.CTk" id="ctk1">
    <property name="geometry">320x200</property>
    <child>
      <object class="customtkinter.CTkFrame" id="ctkframe2">
        <layout manager="pack">
          <property name="expand">true</property>
          <property name="fill">both</property>
          <property name="side">top</property>
        </layout>
        <child>
          <object class="customtkinter.CTkLabel" id="ctklabel2">
            <property name="text" translatable="yes">Test App Ctk</property>
            <layout manager="pack">
              <property name="expand">true</property>
              <property name="side">top</property>
            </layout>
          </object>
        </child>
      </object>
    </child>
  </object>
</interface>

example.py

#!/usr/bin/python3
import pathlib
import pygubu
PROJECT_PATH = pathlib.Path(__file__).parent
PROJECT_UI = PROJECT_PATH / "example.ui"

class ExampleApp:
    def __init__(self, master=None):
        self.builder = builder = pygubu.Builder()
        builder.add_resource_path(PROJECT_PATH)
        builder.add_from_file(PROJECT_UI)
        # Main widget
        self.mainwindow = builder.get_object("ctk1", master)
        builder.connect_callbacks(self)

    def run(self):
        self.mainwindow.mainloop()

if __name__ == "__main__":
    app = ExampleApp()
    app.run()
Sgambe33 commented 1 year ago

I have CtkTopLevel as main widget, that's probably why then. I'll switch to Ctk class