• tkinter简单使用


    第一个运行程序

    # -*- coding: utf-8 -*-
    import tkinter as tk   //引入
    root = tk.Tk()     // 实例化root    T大写k小写
    root.title('Demo')
    theLabel = tk.Label(root, text='我的第二个窗口程序!')
    theLabel.pack()
    root.mainloop()

    ###运行###

    ###部分参数###

    pack(side =tk.LEFT, padx =0, pady=0) 靠左
    pack(side =tk.TOP, padx =0, pady=0) 靠上
    pack(side =tk.RIGHT, padx =0, pady=0) 靠右
    pack(side =tk.TOTTOM, padx =0, pady=0) 靠下
    text = '文字'
    bg = '' 背景色
    fg = '' 前景色、
    #窗口居中显示
    root.geometry('%dx%d+%d+%d' % (width,height,(root.winfo_screenwidth() - width ) / 2, (root.winfo_screenheight() - height) / 2))
    #窗口最大值
    root.maxsize(600,600)
    #窗口最小值
    root.minsize(600,600)

    结合面向对象

     

    import tkinter as tk
    class App():
        def __init__(self,root):
            frame = tk.Frame(root)
            frame.pack(side=tk.LEFT, padx=2)
            self.hi = tk.Button(frame, text='点击我', fg ='white', bg='red',command = self.hello)
            self.hi.pack()
        def hello(self):
            print 'hello!'
    root = tk.Tk()
    root.title("TkinterSimple")
    width ,height= 600, 600
    #窗口居中显示
    root.geometry('%dx%d+%d+%d' % (width,height,(root.winfo_screenwidth() - width ) / 2, (root.winfo_screenheight() - height) / 2))
    #窗口最大值
    root.maxsize(600,600)
    #窗口最小值
    root.minsize(600,600)
    app = App(root)
    root.mainloop()

    ###运行###

    设计的确不美观,对齐的话的确不好操作,但是可以通过别的方法。

  • 相关阅读:
    团队冲刺第二天
    电梯演讲的准备——冰淇淋第一个项目NABCD分析
    团队冲刺第四天
    团队冲刺第六天
    团队冲刺第三天
    团队冲刺第一天
    XmlDocument类的WriteContentTo和WriteTo方法
    从一场DOTA对战中发现的哲理,也做为对2012年的展望
    String.Trim()真相大揭秘
    SQL Server 2008数据库维护计划
  • 原文地址:https://www.cnblogs.com/shuangzikun/p/python_taotao_tkinter_first.html
Copyright © 2020-2023  润新知