按钮preSS交换接口 [英] Swap interface on button press

查看:149
本文介绍了按钮preSS交换接口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新来的Tkinter,我想创建一个在pressed显示第2个接口的按钮。我写了下面的程序:

I am new to Tkinter and I want to create a button which when pressed displays a 2nd interface. I have written the following program:

import Tkinter

root = Tkinter.Tk(  )
root.title("My First Game")

for r in range(3):
    for c in range(3):
            Tkinter.Label(root, text= '3', borderwidth=20 ).grid(row=1,column=1)
        Tkinter.Label(root, text= '6', borderwidth=20 ).grid(row=1,column=2)
        Tkinter.Label(root, text= '4', borderwidth=20 ).grid(row=1,column=3)
        Tkinter.Label(root, text= '2', borderwidth=20 ).grid(row=2,column=1)
        Tkinter.Label(root, text= '7', borderwidth=20 ).grid(row=2,column=2)
        Tkinter.Label(root, text= ' ', borderwidth=20 ).grid(row=2,column=3)
        Tkinter.Label(root, text= '5', borderwidth=20 ).grid(row=3,column=1)
        Tkinter.Label(root, text= '1', borderwidth=20 ).grid(row=3,column=2)
        Tkinter.Label(root, text= '8', borderwidth=20 ).grid(row=3,column=3)

def mainprg():
    for r in range(3):
        for c in range(3):
            Tkinter.Label(root, text= '3', borderwidth=20 ).grid(row=1,column=1)
            Tkinter.Label(root, text= '6', borderwidth=20 ).grid(row=1,column=2)
            Tkinter.Label(root, text= ' ', borderwidth=20 ).grid(row=1,column=3)
            Tkinter.Label(root, text= '2', borderwidth=20 ).grid(row=2,column=1)
            Tkinter.Label(root, text= '7', borderwidth=20 ).grid(row=2,column=2)
            Tkinter.Label(root, text= '4', borderwidth=20 ).grid(row=2,column=3)
            Tkinter.Label(root, text= '5', borderwidth=20 ).grid(row=3,column=1)
            Tkinter.Label(root, text= '1', borderwidth=20 ).grid(row=3,column=2)
            Tkinter.Label(root, text= '8', borderwidth=20 ).grid(row=3,column=3)


B = Tkinter.Button(text = "Run", command = mainprg)
B.pack()

root.mainloop()

我想显示的第一个界面和<大骨节病>运行按钮。 pressing的<大骨节病>运行按钮后第二个界面显示。但是运行上面的code后,它不会显示任何内容。

I am trying to display the first interface and the Run button. After pressing the Run button the 2nd interface is to be displayed. But after running the above code, it does not display anything.

推荐答案

您在混合电网(这是一个坏主意,如见 http://stackoverflow.com/a/3968033/3001761 );的 B 分配更改为:

You are mixing grid and pack (this is a bad idea, see e.g. http://stackoverflow.com/a/3968033/3001761); change the assignment of B to:

B = Tkinter.Button(text = "Run", command = mainprg)
B.grid(row=4, column=1)

另外,你的循环做同样的事情没有明显原因的9倍;你或许应该重新思考的逻辑。

Also, your for loops do the same thing 9 times for no apparent reason; you should probably re-think the logic.

这篇关于按钮preSS交换接口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆