如何在Python FMX GUI应用程序中创建一个选项卡控件?

huangapple go评论71阅读模式
英文:

How do I create a tabbed control in a Python FMX GUI App?

问题

I'm making a Python FMX GUI App and I basically want three tabs on it like this:
如何在Python FMX GUI应用程序中创建一个选项卡控件?

I tried doing this:

self.TabControl1 = TabControl(self)
self.TabControl1.Parent = self
self.TabControl1.Align = "Client"
self.TabControl1.Margins.Top = 50
self.TabControl1.Margins.Bottom = 50
self.TabControl1.Margins.Left = 50
self.TabControl1.Margins.Right = 50

self.TabControl1.Tabs.Add("Tab1")
self.TabControl1.Tabs.Add("Tab2")
self.TabControl1.Tabs.Add("Tab3")

The self.TabControl1.Tabs.Add() fails and errors with AttributeError: Error in getting property "Tabs". Error: Unknown attribute.

What is the correct way to give tabs to the TabControl component?

英文:

I'm making a Python FMX GUI App and I basically want three tabs on it like this:
如何在Python FMX GUI应用程序中创建一个选项卡控件?

I tried doing this:

self.TabControl1 = TabControl(self)
self.TabControl1.Parent = self
self.TabControl1.Align = "Client"
self.TabControl1.Margins.Top = 50
self.TabControl1.Margins.Bottom = 50
self.TabControl1.Margins.Left = 50
self.TabControl1.Margins.Right = 50

self.TabControl1.Tabs.Add("Tab1")
self.TabControl1.Tabs.Add("Tab2")
self.TabControl1.Tabs.Add("Tab3")

The self.TabControl1.Tabs.Add() fails and errors with AttributeError: Error in getting property "Tabs". Error: Unknown attribute.

What is the correct way to give tabs to the TabControl component?

答案1

得分: 0

以下是代码的中文翻译部分:

# 使用以下代码创建一个选项卡:
self.TabItem1 = TabItem(self.TabControl1)
self.TabItem1.Text = "选项卡 1"
self.TabItem1.Parent = self.TabControl1

# 这里是创建一个类似你发布的 `Form` 上的三个选项卡的完整代码:
from delphifmx import *

class frmMain(Form):
    def __init__(self, owner):
        self.Caption = '带有三个选项卡的我的应用'
        self.Width = 1000
        self.Height = 500

        self.TabControl1 = TabControl(self)
        self.TabControl1.Parent = self
        self.TabControl1.Align = "Client"
        self.TabControl1.Margins.Top = 50
        self.TabControl1.Margins.Bottom = 50
        self.TabControl1.Margins.Left = 50
        self.TabControl1.Margins.Right = 50

        self.TabItem1 = TabItem(self.TabControl1)
        self.TabItem1.Text = "第一个选项卡"
        self.TabItem1.Parent = self.TabControl1

        self.TabItem2 = TabItem(self.TabControl1)
        self.TabItem2.Text = "第二个选项卡"
        self.TabItem2.Parent = self.TabControl1

        self.TabItem3 = TabItem(self.TabControl1)
        self.TabItem3.Text = "第三个选项卡"
        self.TabItem3.Parent = self.TabControl1

def main():
    Application.Initialize()
    Application.Title = "我的应用"
    Application.MainForm = frmMain(Application)
    Application.MainForm.Show()
    Application.Run()
    Application.MainForm.Destroy()

if __name__ == '__main__':
    main()

这是创建一个带有选项卡的 Python GUI 应用的代码。

英文:

You can use the following code to create a tab:

self.TabItem1 = TabItem(self.TabControl1)
self.TabItem1.Text = "tab 1"
self.TabItem1.Parent = self.TabControl1

Here's the full code to create 3 tabs on a Form similar to the one you posted:

from delphifmx import *

class frmMain(Form):
    def __init__(self, owner):
        self.Caption = 'My Application with three tabs'
        self.Width = 1000
        self.Height = 500

        self.TabControl1 = TabControl(self)
        self.TabControl1.Parent = self
        self.TabControl1.Align = "Client"
        self.TabControl1.Margins.Top = 50
        self.TabControl1.Margins.Bottom = 50
        self.TabControl1.Margins.Left = 50
        self.TabControl1.Margins.Right = 50

        self.TabItem1 = TabItem(self.TabControl1)
        self.TabItem1.Text = "Your first tab"
        self.TabItem1.Parent = self.TabControl1

        self.TabItem2 = TabItem(self.TabControl1)
        self.TabItem2.Text = "Your second tab"
        self.TabItem2.Parent = self.TabControl1

        self.TabItem3 = TabItem(self.TabControl1)
        self.TabItem3.Text = "Your third tab"
        self.TabItem3.Parent = self.TabControl1


def main():
    Application.Initialize()
    Application.Title = "My Application"
    Application.MainForm = frmMain(Application)
    Application.MainForm.Show()
    Application.Run()
    Application.MainForm.Destroy()

if __name__ == '__main__':
    main()

如何在Python FMX GUI应用程序中创建一个选项卡控件?

huangapple
  • 本文由 发表于 2023年3月7日 00:35:02
  • 转载请务必保留本文链接:https://go.coder-hub.com/75653432.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定