zoukankan      html  css  js  c++  java
  • Python GUI tkinter窗口视窗学习2

    Python GUI tkinter窗口视窗学习2

    test4
    import tkinter as tk
    # 实例化object,建立窗口
    window = tk.Tk()
    window.title('my test')
    # 设置窗口的大小
    window.geometry('500x300')       # 这里的乘号是小写的x
    # 在界面上设置标签
    var = tk.StringVar()  # 将label标签的内容设置为字符类型,用var来接收hit_me函数的传出内容用以显示在标签上
    l = tk.Label(window,textvariable = var,bg = 'olive',width = 30,height = 2)
    # 放置标签  两种方法: l.pack()   2. l.place()
    l.pack()
    
    # button相关内容
    on_hit = False
    def click():
    	global on_hit
    	if on_hit == False:
    		on_hit = True
    		var.set("clicked  hhhh")
    	else:
    		on_hit = False
    		var.set('')
    # 放置button按键
    b = tk.Button(window,text = 'hit',width = 10,height = 1,command = click)
    b.pack()
    
    # 主窗口循环显示
    window.mainloop()
    


    test5
    Entry 输入

    # test5
    # Entry:输入
    import tkinter as tk
    window = tk.Tk()
    window.title('呵呵')
    window.geometry('700x400')
    e1 = tk.Entry(window,show = '*')   # 显示密文格式
    e2 = tk.Entry(window,show = None)  # 显示明文格式
    e1.pack()
    e2.pack()
    window.mainloop()
    

    test6
    import tkinter as tk
    window = tk.Tk()
    window.title('hhhh')
    window.geometry('700x400')
    var1 = tk.StringVar()    # 创建变量,接收点击的具体选项的内容
    l = tk.Label(window,bg = 'green',fg = 'yellow',width = 10,textvariable = var1)
    l.pack()
    def print_selection():
    	value = lb.get(lb.curselection())
    	var1.set(value)
    b1 = tk.Button(window,text = 'print_selection',width = 15,height = 2,command = print_selection)
    b1.pack()
    var2 = tk.StringVar()
    var2.set((1,2,3,4))
    # 创建Listbox    把var2的值赋给listbox
    lb = tk.Listbox(window,listvariable = var2)
    
    list_items = [11,22,33,44]
    for item in list_items:
    	lb.insert('end',item)
    lb.pack()
    window.mainloop()
    

    # test8
    import tkinter as tk
    window = tk.Tk()
    window.title('my test8')
    window.geometry('700x400')
    var  = tk.StringVar()
    l = tk.Label(window,bg = 'green',width = 20,text = 'empty')
    l.pack()
    def print_selection():
    	l.config(text = 'you have selected'+var.get())
    r1 = tk.Radiobutton(window,text = 'option1',variable = var,value = '1',command = print_selection)	
    r1.pack()
    r2 = tk.Radiobutton(window,text = 'option2',variable = var,value = '2',command = print_selection)	
    r2.pack()
    r3 = tk.Radiobutton(window,text = 'option3',variable = var,value = '3',command = print_selection)	
    r3.pack()
    window.mainloop()
    
    


    最后赋的是value的值

  • 相关阅读:
    【LeetCode】119. Pascal's Triangle II
    随机梯度下降(Stochastic gradient descent)和 批量梯度下降(Batch gradient descent )的公式对比、实现对比[转]
    linux下一些可用库
    malloc分配的内存空间是连续的吗
    语言模型训练网站
    relocation 错误
    undefined reference to `dlopen'
    静态库之间有依赖关系顺序很重要
    C++引用详解
    malloc原理和内存碎片[转]
  • 原文地址:https://www.cnblogs.com/serendipity-my/p/13715262.html
Copyright © 2011-2022 走看看