我该如何以我想要的方式设置此GUI?

发布于 2025-01-21 19:29:00 字数 838 浏览 1 评论 0原文

我正在使用Guizero在Python中制作一个简单的GUI,我希望它看起来很像:

但是我正在编码,由于某种原因,我得到了一个空白的空间,这正在移动我的元素。另外,我在底部框中对齐底部,但是除非我使窗户增长,否则它们不会显示: 当我使窗户生长时,两个盒子出现了:

这是我的代码:

我在做什么错?我真的没有找到有关Guizero的文档

I'm using Guizero to make a simple GUI in Python, and I want it to look pretty much like this:
This is the GUI I want

But I'm coding and for some reason I'm getting a blank space which is moving my elements. Also, I'm usign align bottom in my bottom boxes but they don't show unless I make the window grow:
Blank space for no reason
When I make the window grow the two boxes appear:
:)

And this is my code:
Simple code

What am I doing wrong? I didn't really find much documentation on Guizero

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

慢慢从新开始 2025-01-28 19:29:00

Guizero的文档在这里: https://lawsie.github.io/guizero/ ,单击小部件菜单下拉菜单。我觉得很好。

使用Guizero很简单,但并不容易。它可以做到它做的事情,但是很难做到自己真正想要做的事情。

我发现,必须将它们放在表格的每个功能区域中的盒子中,以阻止他们在吉泽尔中的对象,以阻止他们决定自己想要的位置。在您的情况下,左右框需要在顶部和底部框之间的“中间”框中。这摆脱了额外的空间。

我还发现,我需要添加填充物以阻止对象离边缘太近,并且彼此之间,并在网格布局中强迫布局。对于填充,我使用带有空文本的“文本”小部件,并以宽度和高度属性为文本小部件的字符大小来控制其大小。

我已经大致说明了您所说的您想要的话。注意中间箱和填充“文本”小部件,尤其是在网格中的按钮周围。还要注意,尽管剩下对齐,但选项和输入文本仍会变化,嗯。

由下面的代码产生的表单

    from guizero import App, Text, TitleBox, Box, TextBox, CheckBox, PushButton
    app = App(title="Restaurante")
    app.width = 1280
    topHeight = 100
    middleHeight = 500
    bottomHeight = 100
    app.height = topHeight + middleHeight + bottomHeight
    rightWidth = 380
    leftWidth = 900
    app.width = rightWidth + leftWidth
    paddingHeight = 1

    topBox = Box(app, align="top", width= "fill", height= topHeight, border= True)
    padding01 = Text(topBox, text="", height = paddingHeight)
    message = Text(topBox, text="TOP BOX", align="top", height = 1, size = 18)
    padding02 = Text(topBox, text="", height = paddingHeight)
    #messagel = Text(app, text="DeLeitese con nuestros exquisitos pLatos")

    middleBox = Box(app, align="top", width= "fill", height= middleHeight, border= True)
    leftBox = Box(middleBox, width= leftWidth, height= middleHeight, border= True, align="left", layout="grid")
    inputLabel01 = Text(leftBox, text="Input01", grid=[0,0], width = 20, size = 14, align="left")
    inputText01 = TextBox(leftBox, text="Type Input01 here", width = 40, grid=[1,0])
    inputLabel02 = Text(leftBox, text="Inp02", grid=[0,1], width = 20, size = 14, align="left")
    inputText02 = TextBox(leftBox, text="Type Inp02 here", width = 40, grid=[1,1])
    inputLabel03 = Text(leftBox, text="Input03", grid=[0,2], width = 20, size = 14, align="left")
    inputText03 = TextBox(leftBox, text="Type Input03 here", width = 40, grid=[1,2])

    rightBox = Box(middleBox, width= rightWidth, height=middleHeight, border= True, layout="grid")
    option01 = CheckBox (rightBox, text="", width = 2, grid=[0,0])
    option01Text = Text (rightBox, text="Option01                      ", width = 30, align="left", grid=[1,0])
    paddingOpt01 = Text(topBox, text="", height = paddingHeight)
    option02 = CheckBox (rightBox, text="", width = 2, grid=[0,1])
    option02Text = Text (rightBox, text="Option02 is really gigantic   ", width = 30, align="left", grid=[1,1])
    paddingOpt02 = Text(topBox, text="", height = paddingHeight)
    option03 = CheckBox (rightBox, text="", width = 2, grid=[0,2])
    option03Text = Text (rightBox, text="Option03                      ", width = 30, align="left", grid=[1,2])
    paddingOpt03 = Text(topBox, text="", height = paddingHeight)

    bottomBox = Box(app, align="top", width= "fill", height= bottomHeight, border= True)
    leftBottomBox = Box(bottomBox, align= "left",width= leftWidth, height= bottomHeight, border= True, layout = "grid")
    paddingBot00 = Text(leftBottomBox, text="", width = 20, height = paddingHeight, grid = [0,0])
    paddingBot10 = Text(leftBottomBox, text="", width = 20, height = paddingHeight, grid = [1,0])
    message = Text(leftBottomBox, text="LEFT BOTTOM BOX", grid = [2,0])
    paddingBot01 = Text(leftBottomBox, text="", width = 20, height = paddingHeight, grid = [0,1])
    buttonOK = PushButton(leftBottomBox, text="OK", width = 20, height = 1, grid = [1,1])
    paddingBot21 = Text(leftBottomBox, text="", width = 20, height = paddingHeight, grid = [2,1])
    buttonCancel = PushButton(leftBottomBox, text="Cancel", width = 20, height = 1, grid = [3,1])
    rightBottomBox = Box(bottomBox, align= "right",width= rightWidth, height=bottomHeight, border= True)
    message = Text(rightBottomBox, text="RIGHT BOTTOM BOX")
    app.display()

Documentation for Guizero is here: https://lawsie.github.io/guizero/, click on the Widgets menu dropdown. I find it pretty good.

Using guizero is simple but not easy. It does what it does but, it is difficult to get it to do what you really want it to do.

I find that one has to constrain objects in guizero, to stop them deciding themselves where they want to be, by putting them in boxes in each functional area of your form. In your case the left and right boxes need to be in a "middle" box between your top and bottom boxes. This gets rid of the extra space.

I also find that I need to add padding to stop objects being too close to edges and to each other, and to force the layout, for example, in grid layout. For padding I use a "Text" widget with empty text, and control its size with the width and height properties which are character sizes for the text widget.

I have made a rough example of what you said that you wanted. Note the middleBox, and the padding "Text" widgets especially around the buttons in the grid. Note also that the option and input text varies position in spite of being left aligned, ah well.

Form produced by the code below

    from guizero import App, Text, TitleBox, Box, TextBox, CheckBox, PushButton
    app = App(title="Restaurante")
    app.width = 1280
    topHeight = 100
    middleHeight = 500
    bottomHeight = 100
    app.height = topHeight + middleHeight + bottomHeight
    rightWidth = 380
    leftWidth = 900
    app.width = rightWidth + leftWidth
    paddingHeight = 1

    topBox = Box(app, align="top", width= "fill", height= topHeight, border= True)
    padding01 = Text(topBox, text="", height = paddingHeight)
    message = Text(topBox, text="TOP BOX", align="top", height = 1, size = 18)
    padding02 = Text(topBox, text="", height = paddingHeight)
    #messagel = Text(app, text="DeLeitese con nuestros exquisitos pLatos")

    middleBox = Box(app, align="top", width= "fill", height= middleHeight, border= True)
    leftBox = Box(middleBox, width= leftWidth, height= middleHeight, border= True, align="left", layout="grid")
    inputLabel01 = Text(leftBox, text="Input01", grid=[0,0], width = 20, size = 14, align="left")
    inputText01 = TextBox(leftBox, text="Type Input01 here", width = 40, grid=[1,0])
    inputLabel02 = Text(leftBox, text="Inp02", grid=[0,1], width = 20, size = 14, align="left")
    inputText02 = TextBox(leftBox, text="Type Inp02 here", width = 40, grid=[1,1])
    inputLabel03 = Text(leftBox, text="Input03", grid=[0,2], width = 20, size = 14, align="left")
    inputText03 = TextBox(leftBox, text="Type Input03 here", width = 40, grid=[1,2])

    rightBox = Box(middleBox, width= rightWidth, height=middleHeight, border= True, layout="grid")
    option01 = CheckBox (rightBox, text="", width = 2, grid=[0,0])
    option01Text = Text (rightBox, text="Option01                      ", width = 30, align="left", grid=[1,0])
    paddingOpt01 = Text(topBox, text="", height = paddingHeight)
    option02 = CheckBox (rightBox, text="", width = 2, grid=[0,1])
    option02Text = Text (rightBox, text="Option02 is really gigantic   ", width = 30, align="left", grid=[1,1])
    paddingOpt02 = Text(topBox, text="", height = paddingHeight)
    option03 = CheckBox (rightBox, text="", width = 2, grid=[0,2])
    option03Text = Text (rightBox, text="Option03                      ", width = 30, align="left", grid=[1,2])
    paddingOpt03 = Text(topBox, text="", height = paddingHeight)

    bottomBox = Box(app, align="top", width= "fill", height= bottomHeight, border= True)
    leftBottomBox = Box(bottomBox, align= "left",width= leftWidth, height= bottomHeight, border= True, layout = "grid")
    paddingBot00 = Text(leftBottomBox, text="", width = 20, height = paddingHeight, grid = [0,0])
    paddingBot10 = Text(leftBottomBox, text="", width = 20, height = paddingHeight, grid = [1,0])
    message = Text(leftBottomBox, text="LEFT BOTTOM BOX", grid = [2,0])
    paddingBot01 = Text(leftBottomBox, text="", width = 20, height = paddingHeight, grid = [0,1])
    buttonOK = PushButton(leftBottomBox, text="OK", width = 20, height = 1, grid = [1,1])
    paddingBot21 = Text(leftBottomBox, text="", width = 20, height = paddingHeight, grid = [2,1])
    buttonCancel = PushButton(leftBottomBox, text="Cancel", width = 20, height = 1, grid = [3,1])
    rightBottomBox = Box(bottomBox, align= "right",width= rightWidth, height=bottomHeight, border= True)
    message = Text(rightBottomBox, text="RIGHT BOTTOM BOX")
    app.display()
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文