我是 Python 新手,所以我没有尝试或测试过的任何代码。有人知道如何打开一个可以用 Python 运行的空白窗口吗?我知道这可能已经被问到了,但是我找不到。谢谢你。
2 回答
0
使用 tkinter 你可以这样做来打开一个空白窗口:
from tkinter import *
root = Tk()
root.title("Hello this is title")
root.geometry("500x300")
root.mainloop()
于 2021-09-14T14:45:35.273 回答
0
试试这个,应该可以正常工作:
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("hi there, everyone!")
root = tk.Tk()
app = Application(master=root)
app.mainloop()
于 2021-09-14T14:46:20.573 回答