返回顶部

收藏

Radiobuttons demonstration set Font in Text

更多
from Tkinter import *

class RadioFont( Frame ):
   def __init__( self ):
      Frame.__init__( self )
      self.pack( expand = YES, fill = BOTH )
      self.master.title( 'Radiobutton Demo' ) 

      self.frame1 = Frame( self )
      self.frame1.pack()

      self.text = Entry( self.frame1, width = 40, font = 'Arial 10' )
      self.text.insert( INSERT, 'Font Font Font' )
      self.text.pack( padx = 5, pady = 5 )

      self.frame2 = Frame( self )
      self.frame2.pack()

      fontSelections = [ 'Plain', 'Bold', 'Italic', 'Bold/Italic' ]
      self.chosenFont = StringVar()

      self.chosenFont.set( fontSelections[ 0 ] ) 

      for style in fontSelections:
         aButton = Radiobutton( self.frame2, text = style,
            variable = self.chosenFont, value = style,
            command = self.changeFont )
         aButton.pack( side = LEFT, padx = 5, pady = 5 )

   def changeFont( self ):
      desiredFont = 'Arial 10'

      if self.chosenFont.get() == 'Bold':
         desiredFont += ' bold'
      elif self.chosenFont.get() == 'Italic':
         desiredFont += ' italic'
      elif self.chosenFont.get() == 'Bold/Italic':
         desiredFont += ' bold italic'

      self.text.config( font = desiredFont )

def main():
   RadioFont().mainloop()

if __name__ == '__main__':
   main()

标签:Python,2D

收藏

0人收藏

支持

0

反对

0

»更多 您可能感兴趣的代码
  1. 2016-04-23 09:45:22Line width by jack.chen
  2. 2016-02-25 16:20:21Line with pattern by wubai
  3. 2016-09-24 09:03:03Warning bmp on a Label by jack.chen
  4. 2016-11-05 21:19:18Line color by 山药
  5. 2015-12-13 11:28:39Set font from Root component by 风云轩
  6. 2016-01-21 16:07:51Draw circle by 张宋付
  7. 2017-03-05 13:53:41Draw Math Curve by jack.chen
  8. 2015-12-07 19:24:39Load bitmap into a Canvas by 山药
  9. 2016-01-29 16:07:13Label font by 阮小七
  10. 2016-11-08 09:02:07Draw Rectangle by 阮小七
  11. 2017-03-05 14:15:26Set Button style: font by 风云轩
相关聚客文章
  1. 逝去日子 发表 2014-04-15 14:43:01 使用python监控电脑
  2. phithon 发表 2017-01-05 08:27:07 Python 格式化字符串漏洞(Django为例)
  3. Tim 发表 2014-03-24 12:52:32 让你的python代码更加pythonic
  4. admin 发表 2017-01-12 07:33:43 百度图片真实地址解密
  5. asuncool@gmail.com(轻 发表 2014-05-08 00:12:55 一个比较好用的python反编译工具
  6. 博主 发表 2017-01-16 04:07:52 Python metaclass
  7. 龍昌 发表 2014-01-22 11:01:41 使用virtualenv安装多个版本python
  8. 博主 发表 2017-02-12 15:24:36 知乎Live全文搜索之完成爬虫
  9. wsky 发表 2014-05-09 14:38:57 关闭requests日志
  10. mortoray 发表 2017-02-08 15:31:21 Porting Leaf from Linux to OSX
  11. 逝去日子 发表 2014-05-24 03:49:24 使用python登录方正教务管理系统并监控成绩
  12. 李迟 发表 2017-02-14 14:15:40 Python实现阳历转农历功能

发表评论