如何在Python FMX GUI应用程序中设置一个TabControl的活动选项卡?

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

How do I set an active tab for TabControl in a Python FMX GUI App?

问题

我已经创建了一个带有 TabControl 和四个 TabItem 选项卡的 Form。默认情况下,第一个选项卡始终是活动选项卡:

self.TabControl1 = TabControl(self)
self.TabControl1.Parent = self
self.TabControl1.Align = "Client"

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

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

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

self.TabItem4 = TabItem(self.TabControl1)
self.TabItem4.Text = "My fourth tab"
self.TabItem4.Parent = self.TabControl1

如何将不同的选项卡设置为默认选项卡?比如,我想通过代码将第三个选项卡设置为活动选项卡。

英文:

I've made a Form with a TabControl and Four TabItem tabs on the TabControl. By default, the first tab is always the active tab:

如何在Python FMX GUI应用程序中设置一个TabControl的活动选项卡?

self.TabControl1 = TabControl(self)
self.TabControl1.Parent = self
self.TabControl1.Align = "Client"

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

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

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

self.TabItem4 = TabItem(self.TabControl1)
self.TabItem4.Text = "My fourth tab"
self.TabItem4.Parent = self.TabControl1

How do I set a different tab as the default tab? Like, let's say I want to set the third tab as active via code.

答案1

得分: 0

TabControl 组件具有一个名为 ActiveTab 的属性,您可以将其设置为与您的 TabItem 相等以使其处于活动状态。

所以,如果您想将第三个选项卡作为默认的活动选项卡,然后在创建第三个选项卡的代码的末尾添加以下代码行:

self.TabControl1.ActiveTab = self.TabItem3

完整的 TabItem 创建代码如下:

self.TabItem3 = TabItem(self.TabControl1)
self.TabItem3.Text = "My third tab"
self.TabItem3.Parent = self.TabControl1
self.TabControl1.ActiveTab = self.TabItem3  # 将其设置为 ActiveTab

现在,如果您打开应用程序,您的第三个选项卡将默认设置为活动选项卡。

英文:

The TabControl component has an ActiveTab property which you can set equal to your TabItem to make it active.

So if you want to make your third tab as the default active tab, then add the following line of code at the end of your third tab creation code:

self.TabControl1.ActiveTab = self.TabItem3

Full TabItem creation code:

self.TabItem3 = TabItem(self.TabControl1)
self.TabItem3.Text = "My third tab"
self.TabItem3.Parent = self.TabControl1
self.TabControl1.ActiveTab = self.TabItem3 # Sets it as ActiveTab

Now if you open the app, your third tab will be set as active by default:
如何在Python FMX GUI应用程序中设置一个TabControl的活动选项卡?

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

发表评论

匿名网友

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

确定