0

这是我的代码:

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 ()这样做。但是我应该把我的代码放在哪里,以便在忘记以前的小部件的新页面上放置一个新按钮或标签????我希望我是清楚的???

4

1 回答 1

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()
于 2013-08-13T14:49:03.843 回答