Tkinter的基本元件的添加

来源:互联网 发布:视频播放cms 编辑:程序博客网 时间:2024/05/22 06:48

      最近学习了一些关于Python的皮毛,看了看有关Tkinter的GUI编程,Tkinter还是比较简单的一种GUI库,所以上手很快,添加或者是调整元件都很方便。常用的基本就是窗体、按钮、标签、输入文本框、下拉菜单等。事件暂时还没有添加,先保存一份代码供今后参考。

__author__ = 'freedom'import  Tkinterroot = Tkinter.Tk()root.title("test")root.geometry("300x200")button1 = Tkinter.Button(root,anchor=Tkinter.S,text="but1")button1.pack()#button1.place(anchor = Tkinter.N,width = 100,height = 100,relwidth = 0.5,relheight = 0.5)lab1 = Tkinter.Label(root,text = "This is a test!\nPlaese in input",justify = Tkinter.LEFT)lab1.pack()ent1 = Tkinter.Entry(root,show = '*',selectbackground = 'red',selectforeground = 'gray')ent1.pack()menu = Tkinter.Menu(root)submenu = Tkinter.Menu(menu,tearoff = 0)submenu.add_command(label = "open")submenu.add_command(label = "select")submenu.add_separator()submenu.add_command(label = "exit")menu.add_cascade(label = 'File',menu = submenu)root.config(menu = menu)r = Tkinter.StringVar()r.set('0')radio1 = Tkinter.Radiobutton(root,variable = r,value = '1',text = 'radio1')radio1.pack()radio2 = Tkinter.Radiobutton(root,variable = r,value = '2',text = 'radio2')radio2.pack()c = Tkinter.IntVar()c.set(0)check = Tkinter.Checkbutton(root,text = 'check',variable = c,onvalue = 1,offvalue = 2)check.pack()print r.get()print c.get()root.mainloop()


0 0
原创粉丝点击