#自定义界面设计
mybutton = Button(parent, **configuration options)
也可以这么写
mybutton.configure(**options)
颜色可以用rgb 也可以使用颜色标准名或者预定义颜色表示
可在 C:\Python27\Tools\pynche html40colors.txt 看到
# HTML 4.0 color names
Black #000000
Silver #c0c0c0
Gray #808080
White #ffffff
Maroon #800000
Red #ff0000
Purple #800080
Fuchsia #ff00ff
Green #008000
Lime #00ff00
Olive #808000
Yellow #ffff00
Navy #000080
Blue #0000ff
Teal #008080
Aqua #00ffff
字体 样式设置
widget.configure( font= 'font family, fontsize, optional style modifiers
like bold, italic, underline and overstrike')
例子
widget.configure (font='Times, 8')
widget.configure (font = 'Helvetica 24 bold italic')
大小参数 可以使用px 也可以使用m(millimiters),c(centimeters),i(inches)等
Tkinter的边框一般是2px 可以修改 如下:
button.configure(borderwidth=5)
widget有5种浮雕样式:
flat, raised, sunken,groove, an d ridge.
设置如下
button.configure (relief='raised')

鼠标(悬浮状态)样式也可以变化
button.configure (cursor='cross')

为方便自定义样式 可以将样式写在一个txt文件 作为样式数据
*font: Arial 10
*Label*font: Times 12 bold
*background: AntiqueWhite1
*Text*background: #454545
*Button*foreground:gray55
*Button*relief: raised
*Button*width: 3
加*表示 通用于widget的所有元素
root.option_readfile('optionDB.txt')
option_readfile表示调用哪个数据

案例:
root.title("title of my program")
定义标题
root.geometry('142x280+150+200')
定义尺寸和坐标 widthxheight + xoffset + yoffset

self.root.wm_iconbitmap('mynewicon.ico')
or
self.root.iconbitmap('mynewicon.ico ')
修改默认图标
root.overrideredirect(1)
移除框架

案例:
from Tkinter import *
root = Tk()
#demo of some important root methods
root.geometry('142x280+150+200') #specify root window size and position
root.title("Style Demo") #specifying title of the program
#root.wm_iconbitmap('brush1.ico')#changing the default icon
#root.overrideredirect(1) # remove the root border - uncomment
#this line to see the difference
#root.configure(background='#4D4D4D')#top level styling
# connecting to the external styling optionDB.txt
#root.option_readfile('optionDB.txt')
#widget specific styling
mytext = Text(root, background='#101010', foreground="#D6D6D6",
borderwidth=18, relief='sunken', width=16, height=5 )
mytext.insert(END, "Style is knowing \nwho you are, what \nyou want to say, \nand not giving a \ndamn.")
mytext.grid(row=0, column=0, columnspan=6, padx=5, pady=5)
# all the below widgets derive their styling from optionDB.txt file
Button(root, text='*' ).grid(row=1, column=1)
Button(root, text='^' ).grid(row=1, column=2)
Button(root, text='#' ).grid(row=1, column=3)
Button(root, text='<' ).grid(row=2, column=1)
Button(root, text='OK', cursor='target').grid(row=2, column=2)
Button(root, text='>').grid(row=2, column=3)
Button(root, text='+' ).grid(row=3, column=1)
Button(root, text='v', font='Verdana 8').grid(row=3, column=2)
Button(root, text='-' ).grid(row=3, column=3)
for i in range(0,10,1):
Button(root, text=str(i) ).grid( column=3 if i%3==0 else (1 if i%3==1
else 2), row= 4 if i<=3 else (5 if i<=6 else 6))
#styling with built-in bitmap images
mybitmaps = ['info', 'error', 'hourglass', 'questhead', 'question',
'warning']
for i in mybitmaps:
Button(root, bitmap=i, width=20,height=20).grid(row=
(mybitmaps.index(i)+1), column=4,sticky='nw')
root.mainloop()

python之GUI自定义界面设计 2014-4-10的更多相关文章

  1. Python数据结构与算法设计总结篇

    1.Python数据结构篇 数据结构篇主要是阅读[Problem Solving with Python]( http://interactivepython.org/courselib/static ...

  2. PyQt5多个GUI界面设计

    版权声明:本文为博主原创文章,转载 请注明出处:https://blog.csdn.net/sc2079/article/details/90454379 - 写在前面 本科毕业设计终于告一段落了.特 ...

  3. Python 的元类设计起源自哪里?

    一个元老级的 Python 核心开发者曾建议我们( 点击阅读),应该广泛学习其它编程语言的优秀特性,从而提升 Python 在相关领域的能力.在关于元编程方面,他的建议是学习 Hy 和 Ruby.但是 ...

  4. 2014 年10个最佳的PHP图像操作库

    2014 年10个最佳的PHP图像操作库   Thomas Boutell 以及众多的开发者创造了以GD图形库闻名的一个图形软件库,用于动态的图形计算. GD提供了对于诸如C, Perl, Pytho ...

  5. 《Python 数据库 GUI CGI编程》

    本文地址:http://www.cnblogs.com/aiweixiao/p/8390417.html 原文地址 点击关注微信公众号 wenyuqinghuai 1.写在前边 上一次,我们介绍了Py ...

  6. Python的GUI编程(TK)

    TK在大多数 Unix平台.Windows平台和Macintosh系统都是预装好的,TKinter 模块是 Tk GUI 套件的标准Python接口.可实现Python的GUI编程. Tkinter模 ...

  7. python(9): GUI

    实例1: 对输入的所有数字求和, 最后以. 结束输入 def fun(): list1=[] print('input a number:') while True: num=input() if n ...

  8. Python开发GUI工具介绍,实战:将图片转化为素描画!

    欢迎添加华为云小助手微信(微信号:HWCloud002 或 HWCloud003),输入关键字"加群",加入华为云线上技术讨论群:输入关键字"最新活动",获取华 ...

  9. Python开发GUI实战:图片转换素描画工具!

    奋斗没有终点 好好学习72变,因为将来 没有人能替你阻挡81难 . 生如蝼蚁,当有鸿鹄之志: 命如纸薄,应有不屈之心 . ​ 今天被这句话触动了,所以开篇分享给大家.鸡汤有毒,但有时大家却靠它激励自己 ...

随机推荐

  1. 【Helvetic Coding Contest 2018】B2. Maximum Control (medium)

    Description 传送门(翻译就别想了,本人英语太垃圾) Solution 设ans[i]为设置i个船时能控制的最多星球数(看到这你可能因为是dp,然而我可以很负责地告诉你是假的) 首先一个显然 ...

  2. linux下实现多台服务器同步文件(inotify-tools+rsync实时同步文件安装和配置)

    inotify-tools+rsync实时同步文件安装和配置 注:转载https://www.linuxidc.com/Linux/2012-06/63624.htm

  3. php输出中文字符

    中文字符不可以使用imagettftext()函数在图片中直接输出,如果要输出中文字符,需要先使用iconv()函数对中文字符进行编码,语法格式如下:string iconv ( string $in ...

  4. PHP 讓 json_encode() 指定回傳格式

    PHP 回傳 JSON 很方便, 只要將資料經過 json_encode() 就解決了. 不過因為 PHP 自動轉換型別, 造成很多資料都習慣存成字串, 希望在輸出 JSON 的時候, 數字部份可以輸 ...

  5. C#局部类型partial在定义实体类Model中的应用

    以前一直用继承类的方法,原来还可以这样 //例如:定义一个Person的实体类,用户ID(PersonId),姓名(Name),性别(Sex),年龄(Age),地址(Address),联系方式(Tel ...

  6. PetStore项目总结

    数据库(MySQL): account(用户表:没有外键), profile(用户侧面信息表:有两个外键:catid,username), category(宠物总分类表--鱼:没有外键), prod ...

  7. 8.2.6 PEB —— PEB结构值不正确的问题

    书中作者使用 dt _PEB xxxxxx 命令来查看当前进程的PEB结构. 实际操作后PEB结构显示的成员值: 作为进程链表的LDR结构居然没有值,这显然是不正常的,地址也没有输错,问题到底出在哪里 ...

  8. nginx 新手入门

    Nginx 是一个高性能的http 和反向代理服务器,也是一个代理服务器. Nginx比Apache 更加轻量级,占用的资源少,抗并发,二apache是阻塞型的,在高并发下,nginx更占优势. 我们 ...

  9. 主席树-指针实现-找第k小数

    主席树,其实就是N颗线段树 只是他们公用了一部分节点(๑•̀ㅂ•́)و✧ 我大部分的代码是从一位大佬的那里看到的 我这个垃圾程序连Poj2104上的数据都过不了TLE so希望神犇能给我看看, 顺便给 ...

  10. Java中System.setProperty()用法

    /*  * 设置指定键对值的系统属性  * setProperty (String prop, String value);  *  * 参数:  * prop - 系统属性的名称.  * value ...