python之GUI自定义界面设计 2014-4-10
#自定义界面设计
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的更多相关文章
- Python数据结构与算法设计总结篇
1.Python数据结构篇 数据结构篇主要是阅读[Problem Solving with Python]( http://interactivepython.org/courselib/static ...
- PyQt5多个GUI界面设计
版权声明:本文为博主原创文章,转载 请注明出处:https://blog.csdn.net/sc2079/article/details/90454379 - 写在前面 本科毕业设计终于告一段落了.特 ...
- Python 的元类设计起源自哪里?
一个元老级的 Python 核心开发者曾建议我们( 点击阅读),应该广泛学习其它编程语言的优秀特性,从而提升 Python 在相关领域的能力.在关于元编程方面,他的建议是学习 Hy 和 Ruby.但是 ...
- 2014 年10个最佳的PHP图像操作库
2014 年10个最佳的PHP图像操作库 Thomas Boutell 以及众多的开发者创造了以GD图形库闻名的一个图形软件库,用于动态的图形计算. GD提供了对于诸如C, Perl, Pytho ...
- 《Python 数据库 GUI CGI编程》
本文地址:http://www.cnblogs.com/aiweixiao/p/8390417.html 原文地址 点击关注微信公众号 wenyuqinghuai 1.写在前边 上一次,我们介绍了Py ...
- Python的GUI编程(TK)
TK在大多数 Unix平台.Windows平台和Macintosh系统都是预装好的,TKinter 模块是 Tk GUI 套件的标准Python接口.可实现Python的GUI编程. Tkinter模 ...
- python(9): GUI
实例1: 对输入的所有数字求和, 最后以. 结束输入 def fun(): list1=[] print('input a number:') while True: num=input() if n ...
- Python开发GUI工具介绍,实战:将图片转化为素描画!
欢迎添加华为云小助手微信(微信号:HWCloud002 或 HWCloud003),输入关键字"加群",加入华为云线上技术讨论群:输入关键字"最新活动",获取华 ...
- Python开发GUI实战:图片转换素描画工具!
奋斗没有终点 好好学习72变,因为将来 没有人能替你阻挡81难 . 生如蝼蚁,当有鸿鹄之志: 命如纸薄,应有不屈之心 . 今天被这句话触动了,所以开篇分享给大家.鸡汤有毒,但有时大家却靠它激励自己 ...
随机推荐
- 关于bootstrap table的server分页
首先是bootstrap初始化的表格参数: // 初始化Table oTableInit.Init = function() { $('#booksTable').bootstrapTable({ u ...
- Oozie是什么?
但是,一般用Azkaban了.(具体见我写的另一篇博客:) 官网:https://oozie.apache.org/ Oozie is a workflow scheduler system ...
- P3817 小A的糖果
题目描述 小A有N个糖果盒,第i个盒中有a[i]颗糖果. 小A每次可以从其中一盒糖果中吃掉一颗,他想知道,要让任意两个相邻的盒子中加起来都只有x颗或以下的糖果,至少得吃掉几颗糖. 输入输出格式 输入格 ...
- re匹配语法-match、search和findall
1.re.match() 匹配第一个值 列表里的值可以有多个范围,有一个符合就可以. match只匹配第一个值,所以列表里的范围是第一个值得取值范围.如果第一个值被设定好且存在,那么列表的取值范围变为 ...
- 设计 REST API 的13个最佳实践
写在前面 之所以翻译这篇文章,是因为自从成为一名前端码农之后,调接口这件事情就成为了家常便饭,并且,还伴随着无数的争论与无奈.编写友好的 restful api 不论对于你的同事,还是将来作为第三方服 ...
- 使用代码编辑器Sublime Text 3进行前端开发及相关快捷键
推荐理由: Sublime Text:一款具有代码高亮.语法提示.自动完成且反应快速的编辑器软件,不仅具有华丽的界面,还支持插件扩展机制,用她来写代码,绝对是一种享受.相比于浮肿沉重的Eclipse, ...
- 基于Zabbix API文档二次开发与java接口封装
(继续贴一篇之前工作期间写的经验案例) 一. 案例背景 我负责开发过一个平台的监控报警模块,基于zabbix实现,需要对zabbix进行二次开发. Zabbix官方提供了Rest ...
- 使用VS自带WCF测试客户端
打开VS自带WCF测试客户端 打开VS2015 开发人员命令提示 输入:wcftestclient,回车 提取wcftestclient 当然,可以看到VS2015 开发人员命令提示知道,当前路径在C ...
- ubuntu下操作Hadoop、hdfs、hbase、zookeeper时产生的一些问题及解决办法
2019/05/29 1.在终端输入jps时,没有显示Hdfs的DataNode 在文件夹中分别找到DataNode 和Namenode的version,将Datanode的version改为与nam ...
- vector性能调优之resize与reserve
vector的resize与reserve reserve()函数为当前vector预留至少共容纳size个元素的空间.(译注:实际空间可能大于size) resize() 函数( void resi ...