写一段python做可视化界面tkinter
时间: 2023-07-18 10:08:56 浏览: 119
好的,以下是一个简单的Python tkinter可视化界面代码:
```python
import tkinter as tk
class Application(tk.Frame):
def __init__(self, master=None):
super().__init__(master)
self.master = master
self.pack()
self.create_widgets()
def create_widgets(self):
self.hi_there = tk.Button(self)
self.hi_there["text"] = "Hello World\n(click me)"
self.hi_there["command"] = self.say_hi
self.hi_there.pack(side="top")
self.quit = tk.Button(self, text="QUIT", fg="red",
command=self.master.destroy)
self.quit.pack(side="bottom")
def say_hi(self):
print("hello world")
root = tk.Tk()
app = Application(master=root)
app.mainloop()
```
这段代码创建了一个简单的包含一个按钮和退出按钮的界面。当点击 "Hello World" 按钮时,控制台会打印 "hello world"。
阅读全文