第一页忘了把代码放在哪里?

时间:2013-08-12 14:43:12

标签: python python-3.x

这是我的代码:

import sys
from tkinter import *

def forget_page1():
    widgets = [mLabel1, button]
    for widget in widgets:
        widget.place_forget ()

################################
mGui = Tk ()

mGui.geometry("600x600+545+170")
mGui.title("MyMathDictionary")

mLabel1 = Label (text = "Welcome to MyMathDictionary. Press Next to continue.",
                 fg = "blue",bg = "white")
mLabel1.place (x= 150,y = 200)

button = Button (text = "Next", command = forget_page1)
button.place(x = 275,y = 230)

mGui.mainloop()

如果您了解我的代码....有一个页面上有欢迎消息,用户点击“下一步”进入下一页。所以在下一页我必须place_forget ()我做到了。但是,我是否将我的代码放在新页面上放置一个新的按钮或标签,以前忘记了以前的小部件?我希望我很清楚???

1 个答案:

答案 0 :(得分:0)

我可以看到你刚刚开始开发用户界面。故事板是所有事件,在Tk你可以设置自定义信号和插槽,但我认为这个简单的实现现在应该可以工作,我所做的就是调用一个函数来加载新的小部件,注意我还没有测试过此

import sys
from tkinter import *

def forget_page1():
    widgets = [mLabel1, button]
    for widget in widgets:
        widget.place_forget ()
    loadNextPage()

def loadNextPage():
    mLabel2 = Label (text="Welcome to the next page.")
    mLabel2.place (x= 222,y = 200)
    button1 = Button (text = "Hello" )
    button1.place(x = 333,y = 230)

################################
mGui = Tk ()

mGui.geometry("600x600+545+170")
mGui.title("MyMathDictionary")

mLabel1 = Label (text = "Welcome to MyMathDictionary. Press Next to continue.",
                 fg = "blue",bg = "white")
mLabel1.place (x= 150,y = 200)

button = Button (text = "Next", command = forget_page1)
button.place(x = 275,y = 230)

mGui.mainloop()