ceccopierangiolieugenio / pyTermTk

Python Terminal Toolkit - a Spiced Up Cross Compatible TUI Library 🌶️
https://ceccopierangiolieugenio.github.io/pyTermTk-Docs/
MIT License
600 stars 23 forks source link

Windows with Frame #80

Closed nickandwolf closed 1 year ago

nickandwolf commented 1 year ago

Hello! For the life of me, I cannot get frames to render in a window.

ceccopierangiolieugenio commented 1 year ago

Hi, do you have some example code or some picture with the actual/desired results? Maybe you should assign a layout in the window or the frame has zero size.

nickandwolf commented 1 year ago

Please ignore my filler text.

https://replit.com/@NicholasNelson/NaturalBoldCopyrightinfringement#main.py

def main():
    rootLayout = ttk.TTkGridLayout()
    root = ttk.TTk(layout=rootLayout)
    mainWin = ttk.TTkFrame(parent=root, pos=(0, 0), title="", border=True)

    ttk.TTkLabel(parent=mainWin,
                 pos=(1, 1),
                 text="NCPD Punk B.U.S.T.R. - powered by WorldSat",
                 alignment=ttk.TTkK.CENTER_ALIGN)

    def _close(btn):
        pass

    def _test(btn):
        secondWin = ttk.TTkWindow(parent=mainWin,
                                  pos=(4, 4),
                                  size=(30, 10),
                                  title="Shit",
                                  border=True)
        secondWin.menubarTop().addMenu(
            "&X", alignment=ttk.TTkK.RIGHT_ALIGN).menuButtonClicked.connect(
                lambda a: _close(secondWin))
        secondWin.menubarTop().addMenu("TESTSETSET",
                                       alignment=ttk.TTkK.LEFT_ALIGN)
        secondFrame = ttk.TTkFrame(parent=secondWin, title="TESTING", border=True)

        secondFrame.addWidget(ttk.TTkLabel(parent=secondFrame, pos=(2, 2), text="poop"))
        secondWin.addWidget(ttk.TTkLabel(parent=secondFrame,pos=(10,10), text="oh wow"))

    mainWin.menubarTop().addMenu("Campaign").menuButtonClicked.connect(_test)
    mainWin.menubarTop().addMenu("Players")
    mainWin.menubarTop().addMenu("Characters")

    root.mainloop()
nickandwolf commented 1 year ago

I would like to have a window appear. Inside that window is a Frame. Inside that Frame are widgets. Normally this would be done by setting the parent to the container but it doesn't appear to be that simple.

parent->child EX:

Root->Window->Frame->Button

I'm used to Tkinter but I'm banging my head against a wall trying to get nested layouts and containers working.

nickandwolf commented 1 year ago

Alright, got back to my code, put a size and pos for the frame and it appears now. It was just crazy chaos trying to get things working without reverse engineering. Thank you for the prompt reply, sorry for the confusion.

ceccopierangiolieugenio commented 1 year ago

I realised a bug with theclose event, you can workaround temporarely it updating the frame:

https://gist.github.com/ceccopierangiolieugenio/304b9fadb0d619944da568eb41a024a1#file-issue_80_winclose-py-L15

    def _close(win):
        win.close()
        mainWin.update()

you can try it here