用tkinter实现-一个简单的GUI程序,单击“click"按钮,在终端打印出“hello world"。
时间: 2023-05-17 10:06:13 浏览: 165
可以使用以下代码实现:
```python
import tkinter as tk
def print_hello():
print("hello world")
root = tk.Tk()
root.title("Hello World GUI")
button = tk.Button(root, text="click", command=print_hello)
button.pack()
root.mainloop()
```
这个程序创建了一个简单的GUI窗口,其中包含一个按钮。当用户单击按钮时,程序会在终端打印出“hello world”。
相关问题
用tkinter实现一个gui程序,单击“click”按钮,在终端打印出hello world
好的,您可以试试以下代码:
```python
import tkinter as tk
def say_hello():
print("hello world")
root = tk.Tk()
button = tk.Button(root, text="click", command=say_hello)
button.pack()
root.mainloop()
```
当您单击“click”按钮时,终端将打印出“hello world”。希望能帮到您!
. 用tkinter 实现一个简单的 GUI 程序,单击 “click”按钮,在终端打印出“hello world”的代码
好的,以下是一个简单的 tkinter GUI 程序,点击按钮后会在终端打印出 "hello world":
```python
import tkinter as tk
def print_hello():
print("hello world")
root = tk.Tk()
root.geometry("200x100")
root.title("Hello World")
button = tk.Button(root, text="Click", command=print_hello)
button.pack(pady=20)
root.mainloop()
```
这个程序创建了一个窗口,包含一个按钮 "Click"。当点击按钮时,调用 `print_hello` 函数,在终端输出 "hello world"。