#自定义界面设计
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. JAVA常用知识总结(一)

    try catch finally 的详细用法: public static int testBasic(){ int i = 1; try{ i++; System.out.println(&quo ...

  2. ES6学习笔记(11)----Proxy

    参考书<ECMAScript 6入门>http://es6.ruanyifeng.com/ Proxy1.概述    Proxy可以用来修改对象的默认操作    let obj = {na ...

  3. 利用伪类写一个自定义checkbox和radio

    首先是效果图来一张 再来一张html结构 关键的CSS来了~ 首先呢要把input标签设置为display: none;  因为自定义的原理是通过label的for属性,来点击label转向为点击in ...

  4. Backbone.js之Todo源码浅析

    相信每个接触了解过backbone的人都知道todo,网上的关于它的分析教程也都分析乱了.但是,知识只有自己学习领悟才是自己的,话不多说,正文开始. 在分析todo的源码之前,首先我们要知道todo具 ...

  5. netcdf源码在windows上的编译

    作者:朱金灿 来源:http://blog.csdn.net/clever101 今天搞搞netcdf源码在windows上的编译,折腾了半天,算是搞成了,特地记录一下过程.我的目标是要生成netcd ...

  6. mySQL ODBC 在windows 64位版上的驱动问题

    1,问题的起源 某次编辑一个asp文件,其中访问mysql数据库的连接字符串如下: "driver={mysql odbc 3.51 driver};server=localhost;uid ...

  7. php中的define()函数

    <?php define("PI",3.1415926); //定义常量 $r=12;//定义圆半径 echo "半径为12的单位的圆的面积".PI*($ ...

  8. EJB2的配置

    1. ejb-jar.xml <?xml version="1.0" encoding="UTF-8"?> <ejb-jar xmlns=&q ...

  9. 洛谷 P1832 A+B Problem(再升级)

    题目背景 ·题目名称是吸引你点进来的 ·实际上该题还是很水的 题目描述 ·1+1=? 显然是2 ·a+b=? 1001回看不谢 ·哥德巴赫猜想 似乎已呈泛滥趋势 ·以上纯属个人吐槽 ·给定一个正整数n ...

  10. Android(java)学习笔记169:服务(service)之为什么使用服务

    1.服务 service 长期在后台运行的进程,一般没有应用程序界面   2.进程线程和应用程序之间的关系 应用程序开启,系统启动一个Linux进程,所有的组件都是运行在同一个进程的同一个线程(mai ...