首页 > 编程语言 > 详细

Python21-04_页面设计----Practice: place管理器-扑克牌页面设计

时间:2020-09-22 22:37:25      阅读:58      评论:0      收藏:0      [点我收藏+]

Practice: place管理器-扑克牌页面设计

 1 # coding:utf-8
 2 from tkinter import *
 3 from tkinter import messagebox
 4 import random
 5 
 6 
 7 class Application(Frame):
 8     """一个经典的GUI程序类写法"""
 9     def __init__(self, master=None):
10         super().__init__(master)          # super代表的是父类的定义,而不是父类的对象
11         self.master = master
12         self.pack()
13         self.createWidget()
14 
15     def createWidget(self):
16         self.photos = [PhotoImage(file=1/pic+str(i+1)+.gif)for i in range(5)]
17         self.pukes = [Label(self.master, image=self.photos[i])for i in range(5)]
18 
19         for i in range(5):
20             self.pukes[i].place(x=10+i*100, y=50)
21 
22         # 为所有labels加事件处理
23         self.pukes[0].bind_class(Label, <Button-1>, self.chupai)
24 
25     def chupai(self, event):
26         if event.widget.winfo_y() == 50:
27             event.widget.place(y=30)
28         if event.widget.winfo_y() == 30:
29             event.widget.place(y=50)
30 
31 if __name__ == "__main__":
32     root = Tk()
33     root.geometry("800x600+200+100")
34     root.title(canvas)
35     app = Application(master=root)
36     root.mainloop()

技术分享图片

 

Python21-04_页面设计----Practice: place管理器-扑克牌页面设计

原文:https://www.cnblogs.com/xujie-0528/p/13714268.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!