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()

    ###运行###

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

  • 相关阅读:
    UITableView的简单使用
    使用UIScrollView 实现分页功能
    UIScrollView的简单使用
    关于行和列的算法
    block的定义和使用
    plist文件的读取和NSBundle的使用
    UIView的transform属性值详解
    JavaScript _proto_、prototype原型、原型链、constructor构造器、类式继承、原型继承
    javascript 跨域问题
    【javascript知识点】javascript 额外篇
  • 原文地址:https://www.cnblogs.com/shuangzikun/p/python_taotao_tkinter_first.html
Copyright © 2011-2022 走看看