我对python和tkinter相当陌生,但是给出了下面的小示例代码,为什么标签“Hello??”重叠的笔记本标签,应该是它的父。
我的假设是,笔记本作为标签的父节点将导致第0行和第0列(包含框架的)成为笔记本正文本身的左上角,但它似乎不是父节点,而是self.root似乎是父节点,尽管笔记本是作为父对象传递的对象。
将标签网格属性设置为row=1,column=0并不能解决这个问题(据我理解),因为第0行中没有任何内容,因此缩成了零。向row=1设置注意事项时,column=0似乎也不会做任何事情,同样是出于相同的原因。也不将页面框架设置为row=1,column=0。
任何帮助都将不胜感激。
App.py:
#!/usr/bin/env python
from tkinter import Tk;
from tkinter.ttk import Frame, Notebook;
from page import Page;
class Application(Frame):
def __init__(self, parent):
super().__init__(parent);
self.root = parent;
self.root.geometry("450x450+500+500");
self.root.rowconfigure(0, weight=1);
self.root.columnconfigure(0, weight=1);
self.root.grid();
note = Notebook(self.root);
page = Page(note, "pageOne");
note.add(page, text="Page One");
note.grid(sticky="NSEW"); #r=0, c=0 of main window
def main():
root = Tk();
Application(root);
root.mainloop();
if __name__ == '__main__':
main();Page.py:
#!/usr/bin/env python
from tkinter.ttk import Frame, Label;
class Page(Frame):
def __init__(self, parent, name):
super().__init__(parent);
self.root = Frame(parent);
self.name = name;
self.root.grid(); #r=0, c=0 of notebook interior?
Label(self.root, text="Hello???").grid(); #r=0, c=0 also of notebook interior frame发布于 2017-06-09 16:35:34
Page中的所有内容都必须在页面中。您正在父类中创建self.root。这些类不是这样设计的。将这一行改为:
self.root = Frame(self)不过,我认为不需要self.root,因为self已经是Frame了。
https://stackoverflow.com/questions/44462225
复制相似问题