在另一个TabControl中添加新的TabControls

发布于 2025-02-08 10:35:59 字数 2392 浏览 1 评论 0原文

我有一个主要的TabControl(Cronaca)。内部我有第二个TabControl(事件)。

我想将第三个名为“示例”的新标签插入事件中。新的TABCONTROL“示例”必须包含诸如组合蛋白(以前包含在事件中的组合,然后将其从事件中删除)等元素。我该怎么办?

你能告诉我这个简单的代码吗?我知道,我已经将TabControl插入了另一个TabControl,但是我目前感到困惑,并且在Pyhon的早期阶段。帮助对我有用

ps:可选:我的代码可能以无序的方式编写。如果可能的话,有些好人还可以在养蜂的养蜂中订购吗? (前面的五线养殖和之后的五线夫)。谢谢

“

from tkinter import *
from tkinter import ttk
import tkinter as tk


window=Tk()
window.attributes('-zoomed', True)
window.configure(bg='#f3f2f2')

style = ttk.Style(window)
style.theme_use('clam')


#######################
tabControl = ttk.Notebook(window, style='Custom.TNotebook', width=700, height=320)
  
cronaca = ttk.Notebook(tabControl)
politica = ttk.Notebook(tabControl)
gossip = ttk.Notebook(tabControl)

tabControl.add(cronaca, text ='Cronaca')
tabControl.add(politica, text ='Politica')
tabControl.add(gossip, text ='Gossip')
tabControl.place(x=1, y=1)

#CRONACA
a = ttk.Frame(cronaca)
canvas = tk.Canvas(a)

scrollbar = ttk.Scrollbar(a, orient="vertical", command=canvas.yview)
scrollable_frame = ttk.Frame(canvas, width = 500, height = 500)

scrollable_frame.bind(
    "<Configure>",
    lambda e: canvas.configure(
        scrollregion=canvas.bbox("all")
    )
)


canvas.create_window((0, 0), window=scrollable_frame, anchor="nw")
canvas.configure(yscrollcommand=scrollbar.set)


#Incidente
a.pack()
cronaca.add(a, text="Incidente")

combo1=ttk.Combobox(scrollable_frame, width = 18)
combo1.place(x=20, y=20)
combo1['value'] = ["text1", "text2"] 
          
combo2=ttk.Combobox(scrollable_frame, width = 18)
combo2.place(x=20, y=80)
combo2['value'] = ["text1", "text2"] 

combo3=ttk.Combobox(scrollable_frame, width = 18)
combo3.place(x=20, y=140)
combo3['value'] = ["text1", "text2"] 

combo4=ttk.Combobox(scrollable_frame, width = 18)
combo4.place(x=20, y=200)
combo4['value'] = ["text1", "text2"]

canvas.pack(side="left", fill="both", expand=True)
scrollbar.pack(side="right", fill="y")


b = ttk.Frame(cronaca)
cronaca.add(b, text="Microcriminalità")

c = ttk.Frame(cronaca)
cronaca.add(c, text="Criminalità")

d = ttk.Frame(cronaca)
cronaca.add(d, text="Disagi")


#tab 2
c = ttk.Frame(politica)
d = ttk.Frame(politica)


window.mainloop()

I have a Main TabControl (Cronaca). Inside I have a second TabControl (Incident).

I would like to insert a third new TabControl called "Example" into Incident. The new Tabcontrol "Example" will have to contain elements such as those comboboxes (those that were previously contained in Incident, then remove them from Incident). How can I do?

Can you show me this simple code? I know, I have already plugged a Tabcontrol into another Tabcontrol, but I am currently confused and in the early stages of Pyhon. Help will be useful to me

P.S: OPTIONAL: My code is probably written in an unordered way. If it is possible, can some good person also make order in the staves? (the staves that come before and the staves that come after). Thank you

enter image description here

from tkinter import *
from tkinter import ttk
import tkinter as tk


window=Tk()
window.attributes('-zoomed', True)
window.configure(bg='#f3f2f2')

style = ttk.Style(window)
style.theme_use('clam')


#######################
tabControl = ttk.Notebook(window, style='Custom.TNotebook', width=700, height=320)
  
cronaca = ttk.Notebook(tabControl)
politica = ttk.Notebook(tabControl)
gossip = ttk.Notebook(tabControl)

tabControl.add(cronaca, text ='Cronaca')
tabControl.add(politica, text ='Politica')
tabControl.add(gossip, text ='Gossip')
tabControl.place(x=1, y=1)

#CRONACA
a = ttk.Frame(cronaca)
canvas = tk.Canvas(a)

scrollbar = ttk.Scrollbar(a, orient="vertical", command=canvas.yview)
scrollable_frame = ttk.Frame(canvas, width = 500, height = 500)

scrollable_frame.bind(
    "<Configure>",
    lambda e: canvas.configure(
        scrollregion=canvas.bbox("all")
    )
)


canvas.create_window((0, 0), window=scrollable_frame, anchor="nw")
canvas.configure(yscrollcommand=scrollbar.set)


#Incidente
a.pack()
cronaca.add(a, text="Incidente")

combo1=ttk.Combobox(scrollable_frame, width = 18)
combo1.place(x=20, y=20)
combo1['value'] = ["text1", "text2"] 
          
combo2=ttk.Combobox(scrollable_frame, width = 18)
combo2.place(x=20, y=80)
combo2['value'] = ["text1", "text2"] 

combo3=ttk.Combobox(scrollable_frame, width = 18)
combo3.place(x=20, y=140)
combo3['value'] = ["text1", "text2"] 

combo4=ttk.Combobox(scrollable_frame, width = 18)
combo4.place(x=20, y=200)
combo4['value'] = ["text1", "text2"]

canvas.pack(side="left", fill="both", expand=True)
scrollbar.pack(side="right", fill="y")


b = ttk.Frame(cronaca)
cronaca.add(b, text="Microcriminalità")

c = ttk.Frame(cronaca)
cronaca.add(c, text="Criminalità")

d = ttk.Frame(cronaca)
cronaca.add(d, text="Disagi")


#tab 2
c = ttk.Frame(politica)
d = ttk.Frame(politica)


window.mainloop()

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

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

发布评论

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

评论(1

热血少△年 2025-02-15 10:36:00

您可以在“事故”选项卡中创建另一个笔记本,然后将可滚动框架放入新的笔记本中的“示例”选项卡中。

...

#CRONACA
#-- create a Notebook widget inside "cronaca"
incident = ttk.Notebook(cronaca)
#-- add the notebook into the "Incidente" tab
cronaca.add(incident, text="Incidente")

#Incidente
#-- create the scrollable frame inside the "Incidente" tab instead
a = ttk.Frame(incident)
#-- add the scrollable frame into a tab named "Example" inside "Incident" notebook
incident.add(a, text="Example")
...

以下是更新的代码:

# avoid using wildcard import
#from tkinter import *
from tkinter import ttk
import tkinter as tk

window = tk.Tk()  # changed from Tk() to tk.Tk()
window.attributes('-zoomed', True)
window.configure(bg='#f3f2f2')

style = ttk.Style(window)
style.theme_use('clam')

#######################
tabControl = ttk.Notebook(window, style='Custom.TNotebook', width=700, height=320)

cronaca = ttk.Notebook(tabControl)
politica = ttk.Notebook(tabControl)
gossip = ttk.Notebook(tabControl)

tabControl.add(cronaca, text ='Cronaca')
tabControl.add(politica, text ='Politica')
tabControl.add(gossip, text ='Gossip')
tabControl.place(x=1, y=1) # suggest to use pack() instead of place()

#CRONACA
#-- create a Notebook widget inside "cronaca"
incident = ttk.Notebook(cronaca)
#-- add the notebook into the "Incidente" tab
cronaca.add(incident, text="Incidente")

#Incidente
#-- create the scrollable frame inside the "Incident" notebook instead
a = ttk.Frame(incident)
#-- add the scrollable frame into a tab named "Example" inside "Incident" notebook
incident.add(a, text="Example")

canvas = tk.Canvas(a)

scrollbar = ttk.Scrollbar(a, orient="vertical", command=canvas.yview)
scrollable_frame = ttk.Frame(canvas, width = 500, height = 500)

scrollable_frame.bind(
    "<Configure>",
    lambda e: canvas.configure(
        scrollregion=canvas.bbox("all")
    )
)

canvas.create_window((0, 0), window=scrollable_frame, anchor="nw")
canvas.configure(yscrollcommand=scrollbar.set)

combo1=ttk.Combobox(scrollable_frame, width = 18)
combo1.place(x=20, y=20)
combo1['value'] = ["text1", "text2"]

combo2=ttk.Combobox(scrollable_frame, width = 18)
combo2.place(x=20, y=80)
combo2['value'] = ["text1", "text2"]

combo3=ttk.Combobox(scrollable_frame, width = 18)
combo3.place(x=20, y=140)
combo3['value'] = ["text1", "text2"]

combo4=ttk.Combobox(scrollable_frame, width = 18)
combo4.place(x=20, y=200)
combo4['value'] = ["text1", "text2"]

canvas.pack(side="left", fill="both", expand=True)
scrollbar.pack(side="right", fill="y")

b = ttk.Frame(cronaca)
cronaca.add(b, text="Microcriminalità")

c = ttk.Frame(cronaca)
cronaca.add(c, text="Criminalità")

d = ttk.Frame(cronaca)
cronaca.add(d, text="Disagi")

#tab 2
c = ttk.Frame(politica)
d = ttk.Frame(politica)

window.mainloop()

You can create another Notebook inside "Incidente" tab and put the scrollable frame inside a "Example" tab inside the new Notebook.

...

#CRONACA
#-- create a Notebook widget inside "cronaca"
incident = ttk.Notebook(cronaca)
#-- add the notebook into the "Incidente" tab
cronaca.add(incident, text="Incidente")

#Incidente
#-- create the scrollable frame inside the "Incidente" tab instead
a = ttk.Frame(incident)
#-- add the scrollable frame into a tab named "Example" inside "Incident" notebook
incident.add(a, text="Example")
...

Below is the updated code:

# avoid using wildcard import
#from tkinter import *
from tkinter import ttk
import tkinter as tk

window = tk.Tk()  # changed from Tk() to tk.Tk()
window.attributes('-zoomed', True)
window.configure(bg='#f3f2f2')

style = ttk.Style(window)
style.theme_use('clam')

#######################
tabControl = ttk.Notebook(window, style='Custom.TNotebook', width=700, height=320)

cronaca = ttk.Notebook(tabControl)
politica = ttk.Notebook(tabControl)
gossip = ttk.Notebook(tabControl)

tabControl.add(cronaca, text ='Cronaca')
tabControl.add(politica, text ='Politica')
tabControl.add(gossip, text ='Gossip')
tabControl.place(x=1, y=1) # suggest to use pack() instead of place()

#CRONACA
#-- create a Notebook widget inside "cronaca"
incident = ttk.Notebook(cronaca)
#-- add the notebook into the "Incidente" tab
cronaca.add(incident, text="Incidente")

#Incidente
#-- create the scrollable frame inside the "Incident" notebook instead
a = ttk.Frame(incident)
#-- add the scrollable frame into a tab named "Example" inside "Incident" notebook
incident.add(a, text="Example")

canvas = tk.Canvas(a)

scrollbar = ttk.Scrollbar(a, orient="vertical", command=canvas.yview)
scrollable_frame = ttk.Frame(canvas, width = 500, height = 500)

scrollable_frame.bind(
    "<Configure>",
    lambda e: canvas.configure(
        scrollregion=canvas.bbox("all")
    )
)

canvas.create_window((0, 0), window=scrollable_frame, anchor="nw")
canvas.configure(yscrollcommand=scrollbar.set)

combo1=ttk.Combobox(scrollable_frame, width = 18)
combo1.place(x=20, y=20)
combo1['value'] = ["text1", "text2"]

combo2=ttk.Combobox(scrollable_frame, width = 18)
combo2.place(x=20, y=80)
combo2['value'] = ["text1", "text2"]

combo3=ttk.Combobox(scrollable_frame, width = 18)
combo3.place(x=20, y=140)
combo3['value'] = ["text1", "text2"]

combo4=ttk.Combobox(scrollable_frame, width = 18)
combo4.place(x=20, y=200)
combo4['value'] = ["text1", "text2"]

canvas.pack(side="left", fill="both", expand=True)
scrollbar.pack(side="right", fill="y")

b = ttk.Frame(cronaca)
cronaca.add(b, text="Microcriminalità")

c = ttk.Frame(cronaca)
cronaca.add(c, text="Criminalità")

d = ttk.Frame(cronaca)
cronaca.add(d, text="Disagi")

#tab 2
c = ttk.Frame(politica)
d = ttk.Frame(politica)

window.mainloop()
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文