Loading [MathJax]/jax/output/CommonHTML/config.js
前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >专栏 >(转)iOS开发之UICollectionViewController系列(二) :详解CollectionView各种回调

(转)iOS开发之UICollectionViewController系列(二) :详解CollectionView各种回调

作者头像
VV木公子
修改于 2021-03-07 08:30:07
修改于 2021-03-07 08:30:07
7.8K00
代码可运行
举报
文章被收录于专栏:TechBoxTechBox
运行总次数:0
代码可运行

原文链接:https://www.cnblogs.com/ludashi/p/4792480.html

UICollectionView的布局是可以自己定义的,在这篇博客中先在上篇博客的基础上进行扩充,我们先使用UICollectionViewFlowLayout,然后好好的介绍一下UICollectionView的一些回调方法,主要包括UICollectionViewDataSource,UICollectionViewDelegateFlowLayout,UICollectionViewDelegate相关回调方法,并通过实例来介绍每个回调的用法。并且给每个Section添加定制的Header和Footer,好废话少说进入今天的正题。 一、Demo总览 下图是本篇博客中Demo的最终运行效果,下面是我们要做的事情:

  1. 给每个Section添加自定义的重用Header和Footer 2.调整第一个Section的上左下右的边距(UIEdgeInsets) 3.给UICollectioinView设置多选 4.处理Cell的高亮事件 5.处理Cell的选中事件 6.调整Cell的上下左右边距 7.对Cell进行编辑

二、UICollectionViewDataSource介绍 1、在UICollectionViewDataSource回调方法中有一个返回Section数量的方法,如下所示,该方法和UITableView中的用法一致。在这儿我们返回5个Section,如下所示:

Objective-C

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
 #pragma mark 
 
 /**
  * 返回Section的个数
  */
 - (NSInteger)numberOfSectionsInCollectionView: (UICollectionView *)collectionView {
     return 5;
 }

2、在UICollectionViewDataSource的回调方法中,还有一个是返回每个Section中Cell的数量的方法,在这我们返回30个Cell, 如下代码所示:

Objective-C

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
 /**
  * 返回每个Section中Cell的个数
  */
 - (NSInteger)collectionView: (UICollectionView *)collectionView
      numberOfItemsInSection: (NSInteger)section {
 
     return 30;
 }

3、在UICollectionViewDataSource还有一个必须实现的方法, 就是选择我们CollectionView中所使用的Cell, 在这里我们所使用的Cell是在Storyboard上实现的,所以不需要在我们的代码中注册Cell, 之间使用重用标示符就可以获取Cell的对象,如下所示:

Objective-C

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
  /**
   * 返回Cell种类
   */
  - (UICollectionViewCell *)collectionView: (UICollectionView *)collectionView
                    cellForItemAtIndexPath: (NSIndexPath *)indexPath {
 
      //通过Cell重用标示符来获取Cell
      CollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier: reuseIdentifier
                                                                           forIndexPath: indexPath];
 
     return cell;
 }

4、在UICollectionViewDataSource方法中有一个可选的方法就是为我们的Section添加Supplementary View(追加视图),下面是添Supplementary View(追加视图)的步骤。在UICollectionView中的Section中我们可以为其增加Header View和Footer View, 也就是官方文档上提到的Supplementary View(追加视图)。追加视图是可以重用的,也就是UICollectionReusableView。我们可以创建两个UICollectionReusableView的子类,一个是Header View, 另一个是Footer View。 (1)创建UICollectionReusableView 追加视图可以在Storyboard上添加,然后设置重用标示符,在代码中使用即可。这里我们是从xib文件来加载的Supplementary View, 先创建两个UICollectionReusableView子类,在创建该子类的同时创建相应的xib文件,如下所示:

创建Header View和Footer View的UICollectionReusableView,创建后的文件目录如下:

(2) 因为我们是从xib文件中加载的UICollectionReusableView,所以需要在相应的UICollectionView上进行注册。如果你是使用的Storyboard, 只需要在Storyboard中指定重用标示符即可。下面的代码就是在ViewDidLoad中调用注册UICollectionReusableView的方法。

Objective-C

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
  /**
   * 注册Header和FooterView
   * 便于在UICollectionViewDataSource中使用
   */
  - (void) registerHeaderAndFooterView {
      //注册headerView
      //获取含有UICollectionReusableView的Nib文件。
      UINib *headerNib = [UINib nibWithNibName: @"CollectionHeaderReusableView"
                                        bundle: [NSBundle mainBundle]];
 
     //注册重用View
     [self.collectionView registerNib: headerNib
           forSupplementaryViewOfKind: UICollectionElementKindSectionHeader
                  withReuseIdentifier: @"CollectionHeaderReusableView"];
 
     //注册FooterView
     UINib *footerNib = [UINib nibWithNibName: @"CollectionFooterReusableView"
                                       bundle:[ NSBundle mainBundle]];
 
     [self.collectionView registerNib: footerNib
           forSupplementaryViewOfKind: UICollectionElementKindSectionFooter
                  withReuseIdentifier: @"CollectionFooterReusableView"];
 
 }

(3)在UICollectionViewDataSource中的设置Supplementary View的方法中通过Header View和Footer View的重用标示符来为我们的Section设置Supplementary View,具体代码如下所示:

Objective-C

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
  /**
   * 设置Setion的Header和Footer(Supplementary View)
   */
  - (UICollectionReusableView *)collectionView: (UICollectionView *)collectionView
             viewForSupplementaryElementOfKind: (NSString *)kind
                                   atIndexPath: (NSIndexPath *)indexPath{
 
      //设置SectionHeader
      if ([kind isEqualToString: UICollectionElementKindSectionHeader]) {
 
         UICollectionReusableView *view = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"CollectionHeaderReusableView" forIndexPath:indexPath];
 
         return view;
     }
 
     //设置SectionFooter
     UICollectionReusableView *view = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionFooter withReuseIdentifier:@"CollectionFooterReusableView" forIndexPath:indexPath];
     return view;
 
 }

UICollectionViewDataSource中的四个方法在上面都进行了实现,UICollectionViewDataSource主要是负责加载数据源的,包括Section的个数,每个Section中Cell的个数,每个Section中Supplementary View的种类。 三.UICollectionViewDelegateFlowLayout回调实现 UICollectionViewDelegateFlowLayout主要是负责显示的,比如Secion的大小、边距,Cell的大小边距,headerView的大小已经FooterView的大小,都是在UICollectionViewDelegateFlowLayout的相应协议的方法来实现的。接下来详细的介绍一下UICollectionViewDelegateFlowLayout协议中的方法。 1.同一个Section中同一种Cell(通过同一个Cell重用标示符获取的对象)可以有不同的尺寸,下面的代码是给Cell定制尺寸。代码的具体意思是第一个Section中的所有Cell的尺寸是(50,50)。 其余的时(60,60)。

Objective-C

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
  #pragma mark  
  /**
   * 改变Cell的尺寸
   */
  - (CGSize)collectionView: (UICollectionView *)collectionView
                    layout: (UICollectionViewLayout*)collectionViewLayout
    sizeForItemAtIndexPath: (NSIndexPath *)indexPath{
 
      if (indexPath.section == 0) {
         return CGSizeMake(50, 50);
     }
 
     return CGSizeMake(60, 60);
 }

2.改变Section的上下左右边距–UIEdgeInsetsMake(上, 左, 下, 右),逆时针旋转。第一个Section的上左下右的边距都是50, 其余的Section上左下右的边距是0。具体实现看如下代码:

Objective-C

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
  /**
   * Section的上下左右边距--UIEdgeInsetsMake(上, 左, 下, 右);逆时针
   */
  - (UIEdgeInsets)collectionView: (UICollectionView *)collectionView
                          layout: (UICollectionViewLayout*)collectionViewLayout
          insetForSectionAtIndex: (NSInteger)section{
 
      if (section == 0) {
          return UIEdgeInsetsMake(50, 50, 50, 50);
     }
     return UIEdgeInsetsMake(0, 0, 0, 0);
 }

3.设置每个Cell的上下边距的回调如下所示,第一个Section的Cell上下边距是5.0f, 其余的为20.0f。

Objective-C

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
  /**
   * Section中每个Cell的上下边距
   */
  - (CGFloat)collectionView: (UICollectionView *)collectionView
                     layout: (UICollectionViewLayout*)collectionViewLayout
  minimumLineSpacingForSectionAtIndex: (NSInteger)section{
      if (section == 0) {
          return 5.0f;
      }
     return 20.0f;
 }

4.设置Cell的左右边距,第一个Section的Cell左右边距是5.0f, 其余的为20.0f。

Objective-C

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
  /**
   * Section中每个Cell的左右边距
   */
  - (CGFloat)collectionView: (UICollectionView *)collectionView
                     layout: (UICollectionViewLayout*)collectionViewLayout
  minimumInteritemSpacingForSectionAtIndex: (NSInteger)section{
      if (section == 0) {
          return 5.0f;
      }
     return 20.0f;
 }

5.设置Header View和Footer View的大小的回调如下。

Objective-C

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
  /**
   * headerView的大小
   */
  - (CGSize)collectionView: (UICollectionView *)collectionView
                    layout: (UICollectionViewLayout*)collectionViewLayout
  referenceSizeForHeaderInSection: (NSInteger)section{
      return CGSizeMake(200, 50);
  }
 
 /**
  * footerView的大小
  */
 - (CGSize)collectionView: (UICollectionView *)collectionView
                   layout: (UICollectionViewLayout*)collectionViewLayout
 referenceSizeForFooterInSection: (NSInteger)section{
     return CGSizeMake(200, 50);
 }

上面的方法就是UICollectionViewDelegateFlowLayout中所有的方法了,负责布局显示的。 四、UICollectionViewDelegate回调实现 UICollectionViewDelegate中的代理方法主要是负责Cell的交互的,比如是否高亮,是否选,是否可编辑等,接下来要为大家详细的介绍UICollectionViewDelegate中的代理方法。 1.为了这部分的效果展示,我们需要对Cell添加一些控件,并且设置其Highlight和Selected的一些状态。为Cell添加上ImageView, Cell的高亮状态和非高亮状态对应的ImageView上的图片是不同的。再添加一个Button, 并为Button设置Selected和Default状态下的图片,Button的选中和默认状态由Cell的选中状态来定。Cell中改变ImageView的图片的代码如下所示,函数传入的参数是当前Cell的高亮状态,根据高亮状态来设置ImageView上的Image。(有的小伙伴会问为什么给ImageView在Default状态和Highlight下设置不同的图片,然后直接改变ImageView的高亮状态即可。你可以试一下,达不到预期的效果)

Objective-C

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
  - (void) changeHighLightWithBool: (BOOL) highlight{
 
      NSString *imageName = @"003.jpg";
 
      if (highlight) {
          imageName = @"002.jpg";
      }
 
      [_highlightImage setImage: [UIImage imageNamed:imageName]];
 }

2.设置Cell可以高亮, 返回YES代表Cell可以高亮,返回NO代表Cell不可高亮。高亮就是触摸Cell时该Cell变为高亮状态,在代码中的反应就是Cell的Highligth属性变为YES。而触摸结束时,Cell的Highligth属性就变为NO。

Objective-C

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
  #pragma mark
 
  /**
   * Cell是否可以高亮
   */
  - (BOOL)collectionView: (UICollectionView *)collectionView
  shouldHighlightItemAtIndexPath: (NSIndexPath *)indexPath{
 
      return YES;
 
 }

3.下面这个方法是自己写的,用来在界面上反应Cell的高亮状态。 ImageView在当前Cell高亮状态下和非高亮状态下所加载的图片不同,所以可以看出Cell高亮和非高亮。

Objective-C

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
  /**
   * 根据高亮状态修改背景图片
   */
  - (void) changeHighlightCellWithIndexPaht: (NSIndexPath *) indexPath{
      //获取当前变化的Cell
      CollectionViewCell *currentHighlightCell = (CollectionViewCell *)[self.collectionView cellForItemAtIndexPath:indexPath];
 
      [currentHighlightCell changeHighLightWithBool:currentHighlightCell.highlighted];
 
     if (currentHighlightCell.highlighted == YES){
 
         NSLog(@"第%ld个Section上第%ld个Cell变为高亮",indexPath.section ,indexPath.row);
         return;
     }
 
     if (currentHighlightCell.highlighted == NO){
         NSLog(@"第%ld个Section上第%ld个Cell变为非高亮",indexPath.section ,indexPath.row);
     }
 
 }

4.Cell从非高亮变为高亮状态时回调用下面的方法,为了反映Cell的高亮状态,我们去改变一下Cell上ImageView的图片。

Objective-C

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
  /**
   * 如果Cell可以高亮,Cell变为高亮后调用该方法
   */
  - (void)collectionView: (UICollectionView *)collectionView
  didHighlightItemAtIndexPath: (NSIndexPath *)indexPath{
 
      [self changeHighlightCellWithIndexPath:indexPath];
  }
 
 /**
  * 如果Cell可以高亮,Cell从高亮变为非高亮调用该方法
  */
 - (void)collectionView: (UICollectionView *)collectionView
 didUnhighlightItemAtIndexPath: (NSIndexPath *)indexPath{
 
     [self changeHighlightCellWithIndexPath:indexPath];
 
 }

5.设定Cell是否可选的回调如下所示,Cell被选中时该Cell的Selected为YES, 取消选中Selected为NO;

Objective-C

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
 /**
  * Cell是否可以选中
  */
 - (BOOL)collectionView:(UICollectionView *)collectionView shouldSelectItemAtIndexPath:(NSIndexPath *)indexPath{
     return YES;
 }
  1. 如果想让你的Cell支持多选,就需要设定一下CollectionView的allowsMultipleSelection属性,下面的代码是在ViewDidLoad中添加的,如下所示:

Objective-C

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
     //设置Cell多选
     self.collectionView.allowsMultipleSelection = YES;

7.如果在多选状态下需要支持取消Cell的多选,那么就去执行下面的方法,并返回YES。就是支持在多选状态下取消选中状态。

Objective-C

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
 /**
  * Cell多选时是否支持取消功能
  */
 - (BOOL)collectionView:(UICollectionView *)collectionView shouldDeselectItemAtIndexPath:(NSIndexPath *)indexPath{
     return YES;
 }

8.下面这个方法是自己封装的,用来根据Cell的选中状态来改变Cell上Button的选中状态,具体代码实现如下:

Objective-C

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
  /**
   * Cell根据Cell选中状态来改变Cell上Button按钮的状态
   */
  - (void) changeSelectStateWithIndexPath: (NSIndexPath *) indexPath{
      //获取当前变化的Cell
      CollectionViewCell *currentSelecteCell = (CollectionViewCell *)[self.collectionView cellForItemAtIndexPath:indexPath];
 
      currentSelecteCell.selectButton.selected = currentSelecteCell.selected;
 
     if (currentSelecteCell.selected == YES){
         NSLog(@"第%ld个Section上第%ld个Cell被选中了",indexPath.section ,indexPath.row);
         return;
     }
 
     if (currentSelecteCell.selected == NO){
         //NSLog(@"第%ld个Section上第%ld个Cell取消选中",indexPath.section ,indexPath.row);
     }
 
 }

9.在Cell选中和取消选中时都会调用上面的方法来改变Button的选中状态,下面是Cell在选中时以及取消选中时所调用的方法:

Objective-C

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
  /**
   * Cell选中调用该方法
   */
  - (void)collectionView: (UICollectionView *)collectionView
  didSelectItemAtIndexPath: (NSIndexPath *)indexPath{
 
      [self changeSelectStateWithIndexPath:indexPath];
  }
 
 /**
  * Cell取消选中调用该方法
  */
 - (void)collectionView: (UICollectionView *)collectionView didDeselectItemAtIndexPath: (NSIndexPath *)indexPath{
 
     [self changeSelectStateWithIndexPath:indexPath];
 }

10.下方四个方法是Cell将要出现,Cell出现后,Supplementary View将要出现以及Supplementary View已经出现所调用的方法,具体信息请看下方代码实现:

Objective-C

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
  /**
   * Cell将要出现的时候调用该方法
   */
  - (void)collectionView:(UICollectionView *)collectionView willDisplayCell:(UICollectionViewCell *)cell forItemAtIndexPath:(NSIndexPath *)indexPath NS_AVAILABLE_IOS(8_0){
      NSLog(@"第%ld个Section上第%ld个Cell将要出现",indexPath.section ,indexPath.row);
  }
 
  /**
   * Cell出现后调用该方法
  */
 - (void)collectionView:(UICollectionView *)collectionView didEndDisplayingCell:(UICollectionViewCell *)cell forItemAtIndexPath:(NSIndexPath *)indexPath{
     NSLog(@"第%ld个Section上第%ld个Cell已经出现",indexPath.section ,indexPath.row);
 }
 
 /**
  * headerView或者footerView将要出现的时候调用该方法
  */
 - (void)collectionView:(UICollectionView *)collectionView willDisplaySupplementaryView:(UICollectionReusableView *)view forElementKind:(NSString *)elementKind atIndexPath:(NSIndexPath *)indexPath NS_AVAILABLE_IOS(8_0){
 
     NSLog(@"第%ld个Section上第%ld个扩展View将要出现",indexPath.section ,indexPath.row);
 
 }
 
 /**
  * headerView或者footerView出现后调用该方法
  */
 - (void)collectionView:(UICollectionView *)collectionView didEndDisplayingSupplementaryView:(UICollectionReusableView *)view forElementOfKind:(NSString *)elementKind atIndexPath:(NSIndexPath *)indexPath{
 
     NSLog(@"第%ld个Section上第%ld个扩展View已经出现",indexPath.section ,indexPath.row);
 
 }

在UICollectionViewDelegate回调方法中还有三个回调方法是关于Cell编辑的,比如copy, past, cut等操作,具体代码就不在此赘述了。在Demo中给出了实现方式,主要涉及到UIPasteboard的操作,本篇博客的整体的Demo回分享到Github上,下方是Github上的分享链接,感兴趣的小伙伴可以进行Clone。

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2016.02.07 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
暂无评论
推荐阅读
编辑精选文章
换一批
Python实现计算机屏幕任意区域截图
程序功能与用法:运行后有个主窗体,上面有个按钮,单击后开始截图,鼠标坐标落下开始截图,鼠标左键抬起表示截图结束,然后弹出对话框提示保存截图文件。 本文要点在于Python扩展库pillow提供的ImageGrab支持全屏幕或指定区域的截图。 import tkinter import tkinter.filedialog import os from PIL import ImageGrab from time import sleep #创建tkinter主窗口 root = tkinter.Tk() #
Python小屋屋主
2018/04/16
6.2K0
用python实现选择截图区域
一直想用python实现一个类似QQ截图的功能,但不直接截图,而是返回截图的区域,以下是代码
py3study
2020/01/10
3.8K0
Python实现屏幕取色器功能
代码主要思路:首先获取全屏幕截图,在截取的图像上获取指定位置的像素颜色值并转换为十六进制表示形式。 遗憾之处:这个程序的部分代码比较长,在手机上查看时这些换行可能会影响阅读质量,记得之前有个朋友提过建议让我加上代码块,不过我试了试,微信公众号后台的编辑器不支持这个功能,网上找了几个编辑器也不太好用。如果有朋友知道简单易用的支持代码块的编辑器还请推荐一下,谢谢! import os from time import sleep import tkinter import tkinter.filedialog
Python小屋屋主
2018/04/17
7.9K3
Python: 屏幕取色器(识别屏幕上不同位置的颜色)
文章背景:工作中,有时候需要判断图片中不同位置的颜色。有些颜色不太容易区分,所以想通过Python编写代码,通过屏幕取点,获取某个位置的颜色值。
Exploring
2022/09/20
5.2K0
Python:  屏幕取色器(识别屏幕上不同位置的颜色)
基于tkinter的GUI编程
tkinter:tkinter是绑定了Python的TKGUI工具集,就是Python包装的Tcl代码,通过内嵌在Python解释器内部的Tcl 解释器实现的,它是Python标准库的一部分,所以使用它进行GUI编程不需要另外安装第三方库的。
py3study
2020/01/16
5.6K0
基于tkinter的GUI编程
Python实现局域网内屏幕广播的技术要点分析
为更好地保证教学质量和提高学生的学习积极性,我使用Python开发了一套课堂教学管理系统,具有在线点名、在线答疑、随机提问、在线作业管理、在线自测、在线考试、数据汇总、试卷生成、屏幕广播等功能,教师端
Python小屋屋主
2018/04/16
1.5K0
Python实现局域网内屏幕广播的技术要点分析
Python使用tkinter打造自定义对话框完整代码
问题来源:前一阵发过一个技术文章Python编写抽奖式随机提问程序,其中有个弹出式对话框,好像上海科技大学宋老师在群里当时问了一句对话框中中奖姓名是否能显示的大一些,如图: 当时记得标准的tkinte
Python小屋屋主
2018/04/16
3.1K0
Python使用tkinter打造自定义对话框完整代码
tkinter: 事件 & 绑定 (Events and Bindings)
目的 tkinter 获取 键盘输入 与 鼠标输入 。 实现代码 # coding=utf-8 import tkinter as tk root = tk.Tk() def center_window(w, h): # 获取屏幕 宽、高 ws = root.winfo_screenwidth() hs = root.winfo_screenheight() # 计算 x, y 位置 x = (ws/2) - (w/2) y = (hs/2) - (
JNingWei
2018/09/28
7650
Python 图形化界面基础篇:处理鼠标事件
在 Python 图形用户界面( GUI )应用程序开发中,处理鼠标事件是一项重要的任务。鼠标事件包括点击、双击、移动、释放等操作,通过捕获这些事件,你可以实现各种交互功能,如绘图、拖放、点击按钮等。在本文中,我们将深入研究如何使用 Python 的 Tkinter 库来处理鼠标事件,并演示如何在应用程序中实现一些常见的鼠标交互功能。
小蓝枣
2023/09/17
1.2K0
Python 图形化界面基础篇:处理鼠标事件
python截图识别文字_python截图并转换文字「建议收藏」
本文主要介绍了使用pyHook、pythoncom、pytesseract、PIL、win32api等module实现python的截图识别文字功能。
全栈程序员站长
2022/08/13
3.4K0
python截图识别文字_python截图并转换文字「建议收藏」
python tkinter 简单实例
# 1920*1080    表示在屏幕在宽度上上有1920个点, 高度上有1080个点
用户7886150
2020/12/28
2.6K0
python tkinter 设计指南
pack() 是一种较为简单的布局方法,在不使用任何参数的情况下,它会将控件以添加时的先后顺序,自上而下,一行一行的进行排列,并且默认居中显示。pack() 方法的常用参数如下所示:
独元殇
2023/03/21
7.1K0
tkinter -- Event(1)
分别测试鼠标的 Relase 事件,只有当鼠标被 Relase 后移动才回产生 Relase 事件
py3study
2018/08/03
5190
python3 五子棋(tkinter)
BOARD_WIDTH = 535 BOARD_HEIGHT = 536 BOARD_SIZE = 15
用户5760343
2019/12/12
1K0
Python写一个像QQ可快捷键唤起区域截屏的应用
1).首先要能响应快捷键调起截屏程序,像QQ使用Ctrl+shift+B可以截屏一样;
一墨编程学习
2019/05/30
2.4K1
Python--TKinter
GUI介绍 GraphicalUserInterface GUI for Python: TKinter, wxPython, PyQt TKinter: 绑定的是TK GUI工具集,用Python包装的Tcl代码 PyGIK TKinter的替代品 wxPython 跨平台的Python GUI PyQt 跨平台的 商业授权可能有问题 推荐资料 辛星GUI,辛星Python(简洁、清晰) Python GUI Programming cookbook TKinter reference a GUI for
ruochen
2021/05/11
5.3K0
Python--TKinter
快乐游戏,解放双手
上回说到这个PyUserInput这个库能够模拟鼠标和键盘点击(没看过的朋友底部有传送门),今天老肥再来实战一波游戏脚本制作。
老肥码码码
2020/02/26
3500
快乐游戏,解放双手
tkinter学习系列(二)之窗口的设置
目录 (一)窗体的最小框架 1.说明: 2.源代码: 3.实现效果: (二)窗体的基本设置 1.说明: 2.完整代码: 3.实现效果: (三)窗体的外形设置 1.说明: 2.完整代码: 3.实现效果: (四)窗体的三个方法: 1.获取屏幕的大小 2.获取窗体的大小 3.获取窗体的位置 目录: 1.窗体的最小框架 2.窗体的基本设置 3.窗体的外形设置 (一)窗体的最小框架 1.说明: 需要导入标准库: import tkinter 2.源代码: # 导入模块,并取别名 impor
py3study
2020/01/17
1.1K0
python-tkinter(7) 实现各种个样的撩妹鼠标拖尾
系统的拖尾已经无法满足我们了,女朋友叫你把鼠标拖尾换成她的照片,让你时时刻刻都可以看见她,这个要求你答不答应。
全栈程序员站长
2022/07/19
7340
python-tkinter(7) 实现各种个样的撩妹鼠标拖尾
python-tkinter 实现各种个样的撩妹鼠标拖尾
系统的拖尾已经无法满足我们了,女朋友叫你把鼠标拖尾换成她的照片,让你时时刻刻都可以看见她,这个要求你答不答应。
大家一起学编程
2021/09/18
7300
python-tkinter 实现各种个样的撩妹鼠标拖尾
相关推荐
Python实现计算机屏幕任意区域截图
更多 >
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档
本文部分代码块支持一键运行,欢迎体验
本文部分代码块支持一键运行,欢迎体验