Python - GUI链接多个框架

时间:2017-11-13 15:59:18

标签: python user-interface tkinter

使用GUI时非常新,所以想知道是否有人可以给我一些关于如何链接多个帧的指导,这样你就可以按一个按钮进入那个框架。

如果有人有想法或建议会很棒!

var fail1: Extract = { name: "1st failure" }; // does not type check - Missing property "getReadableSchedule"
var fail2: Extract = { getReadableSchedule() { return this.name; } }; // does not type check - Missing property "name";
var fail3: Extract = { // does not type check also! 
    name: "3rd failure", // Ok!
    getReadableSchedule() { return this.name } //Ok!
    id: 1 // Error - property "id" does not exist in type Extract
};

var success: Extract = { 
    name: "Success",
    getReadableSchedule() { return "Ok!"}
}; // <- No errors;

// But it is ok to assign a Variable that has all properties existent 
// in the type and additional ones

var notNamedType = {
    name: "Also works",
    getReadableSchedule() { return this.name },
    id: 1 // property does not exist in the Extract type but...
} 

let alsoWorks: Extract = notNamedType; // no casting needed and works as well;

1 个答案:

答案 0 :(得分:1)

您可以使用命令调用包含嵌套类和新tkinter框架的函数在主类中创建一个按钮,然后您将拥有嵌套的顶级。

import tkinter as tk
class main:
    def __init__(self, root1):
        self.root1=root1
        self.frame1=tk.Frame(root1)
        self.button_spawn_top=tk.Button(text="spawn_frame",
        command=self.new_window)
        self.button_spawn_top.grid(row=0,column=0)
        self.frame1.grid(row=0,column=0)
    def new_window(self):
        class NewWindow:
            def __init__(self, root2):
                self.root2=root2
                self.frame2=tk.Frame(root2)
                self.label2=tk.Label(text='new_window')
                self.label2.grid(row=0,column=0)
                self.frame2.grid(row=0,column=0)
        root2=tk.Toplevel()
        app2=NewWindow(root2)
root1=tk.Tk()
app1=main(root1)
root1.mainloop()