英文:
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:
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:
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()
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论