1.按钮

tkBtton.py

 import tkinter

 root = tkinter.Tk()
 btn1 = tkinter.Button(root, anchor=tkinter.E,\
     text='Button1', width=40, height=5)
 btn1.pack()
 btn2 = tkinter.Button(root, \
     text='Button2', bg='blue')
 btn2.pack()
 btn3 = tkinter.Button(root, \
     text='Button3', width=14, height=1)
 btn3.pack()
 btn4 = tkinter.Button(root, \
     text='Button4', width=60, height=5, state=tkinter.DISABLED)
 btn4.pack()
 root.mainloop()

2.标签

tkLabel.py

 import tkinter

 root = tkinter.Tk()

 lbl1 = tkinter.Label(root, anchor=tkinter.E,
     bg='blue', fg='red', text='Python', width=30, height=5)
 lbl1.pack()

 lbl2 = tkinter.Label(root, text='Python GUI\nTkinter',
     justify=tkinter.LEFT, width=30, height=5)
 lbl2.pack()

 lbl3 = tkinter.Label(root, text='Python GUI\nTkinter',
     justify=tkinter.RIGHT, width=30, height=5)
 lbl3.pack()

 lbl4 = tkinter.Label(root, text='Python GUI\nTkinter',
     justify=tkinter.CENTER, width=30, height=5)
 lbl4.pack()

 root.mainloop()

3.单选框、复选框

tkCheck.py

 import tkinter

 root = tkinter.Tk()

 r = tkinter.StringVar()
 r.set(')
 radio = tkinter.Radiobutton(root, variable=r, value=', text='Radio1')
 radio.pack()

 radio = tkinter.Radiobutton(root, variable=r, value=', text='Radio2')
 radio.pack()

 radio = tkinter.Radiobutton(root, variable=r, value=', text='Radio3')
 radio.pack()

 radio = tkinter.Radiobutton(root, variable=r, value=', text='Radio4')
 radio.pack()

 c = tkinter.IntVar()
 c.set(1)
 check = tkinter.Checkbutton(root, text='CheckButton', variable=c, onvalue=1, offvalue=2)
 check.pack()

 root.mainloop()
 print(r.get())
 print(c.get())

4.单选框、复选框的平坦样式

tkRCButton.py

 import tkinter

 root = tkinter.Tk()

 r = tkinter.StringVar()
 r.set(')
 radio = tkinter.Radiobutton(root, variable=r, value=', text='Radio1', indicatoron=0)
 radio.pack()

 radio = tkinter.Radiobutton(root, variable=r, value=', text='Radio2', indicatoron=0)
 radio.pack()

 radio = tkinter.Radiobutton(root, variable=r, value=', text='Radio3', indicatoron=0)
 radio.pack()

 radio = tkinter.Radiobutton(root, variable=r, value=', text='Radio4', indicatoron=0)
 radio.pack()

 c = tkinter.IntVar()
 c.set(1)
 check = tkinter.Checkbutton(root, text='CheckButton', variable=c, onvalue=1, offvalue=2, indicatoron=0)
 check.pack()

 root.mainloop()
 print(r.get())
 print(c.get())

5.文本框

tkEntry.py

 import tkinter

 root = tkinter.Tk()

 entry1 = tkinter.Entry(root, show='*' )
 entry1.pack()

 entry2 = tkinter.Entry(root, show=')
 entry2.pack()

 entry3 = tkinter.Entry(root, bg='red', fg='blue')
 entry3.pack()

 entry4 = tkinter.Entry(root, selectbackground='red',\
                             selectforeground='gray')
 entry4.pack()

 entry5 = tkinter.Entry(root, state=tkinter.DISABLED)
 entry5.pack()

 edit1 = tkinter.Text(root, selectbackground='red',
                             selectforeground='gray')
 edit1.pack()

 root.mainloop()

Python -- Gui编程 -- Tkinter的使用 -- 基本控件的更多相关文章

  1. Python:GUI之tkinter学习笔记1控件的介绍及使用

    相关内容: tkinter的使用 1.模块的导入 2.使用 3.控件介绍 Tk Button Label Frame Toplevel Menu Menubutton Canvas Entry Mes ...

  2. Python GUI编程(Tkinter) windows界面开发

    Python实现GUI简单的来说可以调用Tkinter库,这样一般的需求都可以实现,显示简单的windows窗口代码如下: python_gui.py 1 #!C:\Python27\python.e ...

  3. Python GUI编程(Tkinter)(一)

    tk官网的教程学习: https://tkdocs.com/tutorial/firstexample.html 学习blog: https://www.cnblogs.com/aland-1415/ ...

  4. Python GUI编程(Tkinter)Ⅱ

    Tkinter 组件 Tkinter的提供各种控件,如按钮,标签和文本框,一个GUI应用程序中使用.这些控件通常被称为控件或者部件. 目前有15种Tkinter的部件.我们提出这些部件以及一个简短的介 ...

  5. python GUI编程tkinter示例之目录树遍历工具

    摘录 python核心编程 本节我们将展示一个中级的tkinter应用实例,这个应用是一个目录树遍历工具:它会从当前目录开始,提供一个文件列表,双击列表中任意的其他目录,就会使得工具切换到新目录中,用 ...

  6. Python GUI编程--Tkinter

    今天看到了GUI编程,书上推荐用wxPython,去官网上看了看,发现Windows的最高支持到2.7,我用的是3.4版本,咋办,用自带的库--Tkinter呗,它是Python的默认GUI库,几乎是 ...

  7. Python -- Gui编程 -- Tkinter的使用 -- 对话框消息框

    1.消息框 tkMessageBox.py import tkinter from tkinter import messagebox def cmd(): global n global butto ...

  8. Python -- Gui编程 -- Tkinter的使用 -- 菜单与画布

    1.菜单 tkMenu.py import tkinter root = tkinter.Tk() menu = tkinter.Menu(root) submenu = tkinter.Menu(m ...

  9. python大法好——ython GUI编程(Tkinter)

    Python GUI编程(Tkinter) Python 提供了多个图形开发界面的库,几个常用 Python GUI 库如下: Tkinter: Tkinter 模块(Tk 接口)是 Python 的 ...

随机推荐

  1. _variant_t与其他数据类型的转换

    转自:http://kuaixingdong.blog.hexun.com/29627840_d.html 我们先看看COM所支持的一些类型的基本类: (微软提供,在comdef.h中定义) 在COM ...

  2. 快速学会在JSP中使用EL表达式

    在没有学会EL表达式之前,我们想在JSP文件中获取servlet或者其他JSP页面传来的值,通常都是在JSP页面中编写java代码来实现.而在jsp页面编写Java 代码,这种做法时不规范的,将会产生 ...

  3. Delphi XE10 dxLayoutControl 控件应用指南

    https://www.cnblogs.com/Bonny.Wong/p/7440288.html DevExpress VCL套件是一套非常强大的界面控件,可惜关于Delphi开发方面的说明太少,有 ...

  4. iOS Development和iOS Distribution有什么区别

    http://zhidao.baidu.com/link?url=T9od33JuA7jjxzfyV-wOjuVLSNUaqpc9aoCu2HjfYfHBuRLW1CNDii0Bh9uvG6h-GeJ ...

  5. Thread in depth 4:Synchronous primitives

    There are some synchronization primitives in .NET used to achieve thread synchronization Monitor c# ...

  6. Git安全配置

      今天收到了阿里云异地登录的短信报警,登录阿里云后台发现,有人从深圳登录了我的服务器(本人在北京),查看详细信息一共登录了5次,前两次是使用的git用户进行登录,后两次已经变成了root用户,怀疑是 ...

  7. ServiceBase.OnStart 方法

    msdn 解释 派生类中实现时,在由服务控制管理器 (SCM) 或在操作系统启动时 (对于自动启动的服务) 时,将启动命令发送到服务时执行. 指定当服务启动时要执行的操作. 命名空间:   Syste ...

  8. c# 协变与抗变

    定义 协变:与原始类型转换方向相同的可变性称为协变. 抗变:与派生类型转换方向相同的可变性称为抗变. 补充: 参数是协变的,可以使用派生类对象传入需要基类参数的方法,反之不行 返回值是抗变的,不能使用 ...

  9. TOJ2470

    #include <stdio.h> struct node{ int x; int y; int step; }first; int zx[4]={-1,0,1,0}; int zy[4 ...

  10. 2.jquery在js中写标准的ajax请求

    $(function(){ $.ajax({ url:"http://www.microsoft.com", //请求的url地址 dataType:"json" ...