Python的Tkinter的打开一个新的窗口,一个按钮提示 [英] Python tkinter open a new window with a button prompt

查看:5126
本文介绍了Python的Tkinter的打开一个新的窗口,一个按钮提示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将能够由用户$ P $在Tkinter的GUI pssing一个按钮,打开一个新窗口?我只需要很简单的解决方案,如果code可能也解释,这将是巨大的。

How would I be able to open a new window by the user pressing a button in a tkinter GUI? I only need quite simple solutions, and if the code could be explained as well that would be great.

推荐答案

下面是近最短的解决你的问题。解决方案的工作在Python 2.x版本对于Python 3.x的更改导入到Tkinter的,而不是Tkinter的

Here's the nearly shortest possible solution to your question. The solution works in python 2.x. For python 3.x change the import to "tkinter" rather than "Tkinter":

import Tkinter as tk

def create_window():
    window = tk.Toplevel(root)

root = tk.Tk()
b = tk.Button(root, text="Create new window", command=create_window)
b.pack()

root.mainloop()

这绝对不是什么我推荐作为良好的编码风格的例子,但它说明了基本概念:用一个命令按钮,并创建一个窗口函数

This is definitely not what I recommend as an example of good coding style, but it illustrates the basic concepts: a button with a command, and a function that creates a window.

这篇关于Python的Tkinter的打开一个新的窗口,一个按钮提示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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