import tkinter as tkclass Application(tk.Frame):def __init__(self, master=None):super().__init__(master)self.pack()self.create_widgets()def create_widgets(self):frame_root = tk.Frame(self)frame_left = tk.Frame(frame_root)frame_left['bg']="#cc4400"frame_right = tk.Frame(frame_root)self.hi_there = tk.Button(frame_left)self.hi_there["text"] = "Hello World\n(click me)"self.hi_there["command"] = self.say_hiself.hi_there.pack(side="left")self.hello_there = tk.Button(frame_right)self.hello_there["text"] = "hello!"self.hello_there["command"] = self.helloself.hello_there.place(x=115,y=15,anchor='nw')self.quit = tk.Button(self, text="QUIT", fg="red",command=root.destroy)self.quit.pack(side="bottom")frame_left.pack(side="left")frame_right.pack(side="right")frame_root.pack();def say_hi(self):print("hi there, everyone!")def hello(self):print("hello")# 创建一个窗口root = tk.Tk()# 背景颜色root["bg"]="#f6f6f6"# 窗口大小root.geometry("900x600")# 长宽不可变root.resizable(width=False,height=False)app = Application(master=root)# 消息循环app.mainloop()
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。