python GUI 实例

来源:转载

#!/usr/bin/env python3# coding=utf-8import tkinter as tkclass Application(tk.Frame): def __init__(self,master=None): tk.Frame.__init__(self,master) self.pack() self.createWidgets() def createWidgets(self): self.hi_there = tk.Button(self) self.hi_there["text"] = "hello python/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=root.destroy) self.QUIT.pack(side="bottom") def say_hi(self): print("hey,look me here!")root = tk.Tk()app = Application(master=root)app.mainloop()


#!/usr/bin/env python3# coding=utf-8import tkinter as tkclass Application(tk.Frame): def __init__(self,master=None): tk.Frame.__init__(self,master) self.pack() self.entrythingy = tk.Entry() self.entrythingy.pack() self.contents = tk.StringVar() self.contents.set("设置属性") self.entrythingy["textvariable"] = self.contents self.entrythingy.bind("<Key-Return>",self.print_contents) def print_contents(self,event): print("当前输入框内容为",self.contents.get()) root = tk.Tk()app = Application(master=root)app.mainloop()


分享给朋友:
您可能感兴趣的文章:
随机阅读: