zoukankan      html  css  js  c++  java
  • 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()

    ###运行###

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

  • 相关阅读:
    ETL开发
    ETL 运行维护
    软件开发的核心
    索引的本质
    也谈谈学习
    oracle内部结构
    [kuangbin带你飞]专题十六 KMP & 扩展KMP & Manacher H
    [kuangbin带你飞]专题十六 KMP & 扩展KMP & Manacher :G
    [kuangbin带你飞]专题十六 KMP & 扩展KMP & Manacher F
    [kuangbin带你飞]专题十六 KMP & 扩展KMP & Manacher E
  • 原文地址:https://www.cnblogs.com/shuangzikun/p/python_taotao_tkinter_first.html
Copyright © 2011-2022 走看看