TK:TCL/TK, Perl/TK, Python/TK(Tkinter)示例
1. TCL/TK
#!/usr/bin/wish # #tcl/tk test #
button.btnHello -text hello -command {puts stdout "hello,world!"} button.btnBye -text Bye! -command {exit}
pack.btnHello -padx 60 -pady 5; #set the length and width pack .btnBye -padx 60 -pady 5; |
2. Perl/TK
#!usr/bin/perl
use strict; use warnings; use Tk;
my $mainWd=new MainWindow; $mainWd->Label(-text=>'hello,world')->pack; $mainWd->Button(-text=>'Quit',-command=>sub{exit})->pack; MainLoop; |
3. python/TK(Tkinter)
import Tkinter def resize(ev=None): label.config(font='Helvetica-%d bold' % scale.get() ) if __name__=='__main__':
top=Tkinter.Tk() #主窗口 top.geometry('600x400') #设置了主窗口的初始大小600x400 top.title('Test') #标题 #图标 top.iconbitmap('D:\\py.ico')
#设置标签字体的初始大小 Initfontsize=12 label=Tkinter.Label(top,text='Hello world!',font='Helvetica-%d bold'%Initfontsize ) label.pack(fill='x',expand=1) #scale创建进度条,设置回调函数 #进度条的始末位置为字体的范围 scale=Tkinter.Scale(top,from_=10,to=40,orient='horizontal',command=resize) scale.set(Initfontsize) #设置起始位置 scale.pack(fill='x',expand=1) # quit对应的command应该填top.destroy函数 quit=Tkinter.Button(top,text='QUIT',command=top.destroy,activeforeground='white',activebackground='red') quit.pack()
#进入消息循环 Tkinter.mainloop() |