如何在tkinter GUI中保持位置

时间:2017-07-24 19:14:59

标签: python-3.x tkinter

我想制作一个看起来像这样的GUI,

 from tkinter import Tk, Text, BOTH, W, N, E, S, END
 from tkinter.ttk import Frame, Button, Label, Style


class Example(Frame):
    def __init__(self):
        super().__init__()

        self.initUI()


    def initUI(self):
        self.master.title("Windows")
        self.pack(fill=BOTH, expand=True)
        self.columnconfigure(1, weight=1)
        self.columnconfigure(3, pad=7)
        self.rowconfigure(3, weight=1)
        self.rowconfigure(5, pad=7)
        lbl = Label(self, text="Windows")
        lbl.grid(sticky=W, pady=4, padx=5)

        area = Text(self)
        area.grid(row=1, column=0, columnspan=2, rowspan=4,
                  padx=5, sticky=E + W + S + N)
        abtn = Button(self, text="Activate", command=lambda: 
        self.print(area.get("1.0", END)))
        abtn.grid(row=1, column=3)

        cbtn = Button(self, text="Close")
        cbtn.grid(row=2, column=3, pady=4)

        hbtn = Button(self, text="Help")
        hbtn.grid(row=5, column=0, padx=5)

        obtn = Button(self, text="OK")
        obtn.grid(row=5, column=3)

    def print(self, area):
        print(area)


    def main():
        root = Tk()
        """Calculate center of screen so popup is center"""
        w = 650
        h = 400

        ws = root.winfo_screenwidth()
        hs = root.winfo_screenheight()

        x = (ws / 2) - (w / 2)
        y = (hs / 2) - (h / 2)
        root.geometry('%dx%d+%d+%d' % (w, h, x, y))
        app = Example()
        root.mainloop()


if __name__ == '__main__':
    main()

enter image description here 但问题是整个空白区域是用文本框制作的。我想在选择特定的东西时放置按钮并更新它在该空间中的样子。所以我可以有不同的"幻灯片"在里面。我想用另一个框架做这个,但我不知道如何制作一个框架或者我可以放入函数和更新的东西,这将保留文本框当前正在创建的空间。

0 个答案:

没有答案