• python的图形化界面(1)


    今天学习了python的图形化界面。

    遇到的问题,就是导入Tklinter类的时候,出现了错误,提示说模块不存在,但是最后在文件的头部添加一行代码之后解决:

    #! /usr/bin/env python
    

      先创建一个空的界面窗口吧:

    #! /usr/bin/env python
    #coding=utf-8
    from Tkinter import *
    
    class LabelDemo( Frame ):
       """Demonstrate Labels"""
       
       def __init__( self ):
          """Create three Labels and pack them"""
          
          Frame.__init__( self )   # initializes Frame instance
    
        
    def main():
       LabelDemo().mainloop()  # starts event loop
    
    if __name__ == "__main__":
       main()
    

      默认的窗口什么都没有,很丑。

    然后先添加几个标签玩玩吧:

    #! /usr/bin/env python
    #coding=utf-8
    from Tkinter import *
    
    class LabelDemo( Frame ):
       """Demonstrate Labels"""
       
       def __init__( self ):
          """Create three Labels and pack them"""
          
          Frame.__init__( self )   # initializes Frame instance
    
          # frame fills all available space
          self.pack( expand = YES, fill = BOTH )
          self.master.title( "Labels" )
    
          self.Label1 = Label( self, text = "Label with text" )
    
          # resize frame to accommodate Label
          self.Label1.pack()
    
          self.Label2 = Label( self,
             text = "Labels with text and a bitmap" )
    
          # insert Label against left side of frame
          self.Label2.pack( side = LEFT )
    
          # using default bitmap image as label
          self.Label3 = Label( self, bitmap = "warning" )
          self.Label3.pack( side = LEFT )
    
    def main():
       LabelDemo().mainloop()  # starts event loop
    
    if __name__ == "__main__":
       main()
    

      注意一下,添加组件的时候,下面这一行代码还是不能少的,笔者也是刚刚接触,说错了大家别喷。

    self.pack()
    

      如果取消这一行的话,其他的组件不能显示。


    ==============================================================================

    本博客已经废弃,不在维护。新博客地址:http://wenchao.ren


    我喜欢程序员,他们单纯、固执、容易体会到成就感;面对压力,能够挑灯夜战不眠不休;面对困难,能够迎难而上挑战自我。他
    们也会感到困惑与傍徨,但每个程序员的心中都有一个比尔盖茨或是乔布斯的梦想“用智慧开创属于自己的事业”。我想说的是,其
    实我是一个程序员

    ==============================================================================
  • 相关阅读:
    android的左右滑动效果实现-ViewFlipper
    ios学习之UISwipeGestureRecognizer手势识别
    iOS使用AVFoundation实现二维码扫描
    IOS开发之Core Location
    iOS中如何创建一个滑出式导航面板(1)
    消息推送之百度云推送Android集成与使用方法
    IOS开发之Storyboard应用
    用CocoaPods做iOS程序的依赖管理
    RelativeLayout 布局参数
    Android中获取应用程序(包)的信息-----PackageManager的使用
  • 原文地址:https://www.cnblogs.com/rollenholt/p/2127454.html
Copyright © 2020-2023  润新知