Python GUI tkinter 学习笔记(二)
第二个程序
# -*- coding: utf-8 -*-from Tkinter import *
class App:
def __init__(self, master):
# frame 创建一个实例
frame = Frame(master)
# 使用pack方法使其可见
frame.pack()
# 定义按钮
self.button = Button(
# 使用系统命令 frame.quit
frame, text = "QUIT", fg = "red", command = frame.quit
)
# 定义位置
self.button.pack(side = LEFT)
# 定义另一个按钮,调用函数
self.hi_there = Button(frame, text = "Hello" ,command = self.say_hi)
self.hi_there.pack(side = LEFT)
# 控制台输出
def say_hi(self):
print "Hello wolrd"
root = Tk()
app = App(root)
root.mainloop()
root.destroy()
草稿
# -*- coding: utf-8 -*-from Tkinter import *
class App:
def __init__(self,master):
frame = Frame(master,height = 100, width = 100 )
# 设置Frame大小
frame.grid(padx=5,pady=5)
frame.pack()
self.label = Label(
frame, text = "url: ",font = ("Arial, 12")
)
self.label.grid(row=0,column=0)
self.label.pack(side = LEFT)
self.textArea = Entry(
frame
)
self.textArea.pack()
self.label.pack(side = LEFT)
root = Tk()
app = App(root)
root.minsize(700,200)
root.mainloop()
root.destroy()
以上是 Python GUI tkinter 学习笔记(二) 的全部内容, 来源链接: utcz.com/z/388402.html