简体   繁体   English

Python tkinter:带滚动条的标签页

[英]Python tkinter: Tab page with scroll bar

I have a tab page with a text box on it and I want to add a scroll bar to it, but it isn't working for me (it is covering the tab name). 我有一个带有文本框的标签页,我想向其中添加滚动条,但是它对我不起作用(它覆盖了标签名)。

Here is my code: 这是我的代码:

*Look below*

Any help would be appreciated! 任何帮助,将不胜感激!

Edit: 编辑:

I am probably being stupid, but now when I switch between tabs the text doesn't change (if I type 'a' and switch between tabs it show up on all of them), and that didn't happen before until I edited the code. 我可能很愚蠢,但是现在当我在选项卡之间切换时,文本不会改变(如果我键入“ a”并在选项卡之间切换时,它会显示在所有选项卡上),直到我编辑了码。 Here is my code; 这是我的代码; let me know if you need more of it: 让我知道您是否需要更多:

tabs = {}
tab_bar = {}

...
def doNew(self):
  # Create a new tab with the file name and select it
  self.nb.select(self.CreateTab())

# Create a new tab
def CreateTab(self, name='Untitled.asm'):

  tab_num = len(tabs)   # get current tab number
  tab_bar_num = len(tab_bar)  # get it's frame as well

  tab_bar[tab_bar_num] = Frame(self.nb)   # create a new frame

  scrollbar = Scrollbar(self.root)
  scrollbar.pack(side=RIGHT, fill=Y)

  tabs[tab_num] = Text(self.root, yscrollcommand=scrollbar.set)
  self.nb.add(tab_bar[tab_bar_num], text=name)   # add tab


  tabs[tab_num].pack(side=LEFT, fill=BOTH)
  scrollbar.config(command=tabs[tab_num].yview)

  return tab_num

Thanks again. 再次感谢。

The tab should be a frame that is a child of the notebook. 该选项卡应该是笔记本的子框架。 Then, the text widget and scrollbar should be in the frame. 然后,文本小部件和滚动条应在框架中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM