鱼C论坛

 找回密码
 立即注册
查看: 1121|回复: 3

[已解决]关于Easygui按键快捷键定义问题

[复制链接]
发表于 2020-11-21 17:53:03 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
本帖最后由 UncleMonster 于 2020-11-21 17:56 编辑

问题如下:
代码1:
  1. import easygui as e

  2. if e.ccbox("文本内容","标题内容",choices = ('按键[a]内容','按键[b]内容')):
  3.     e.msgbox("你选择了按键a的内容")
  4. else:
  5.     e.msgbox("你选择了按键b的内容")
复制代码


代码2:

  1. import easygui as e

  2. if e.ccbox("文本内容","标题内容",choices = ('按键[<a>]内容','按键[<b>]内容')):
  3.     e.msgbox("你选择了按键a的内容")
  4. else:
  5.     e.msgbox("你选择了按键b的内容")
复制代码


代码3:

  1. import easygui as e

  2. if e.ccbox("文本内容","标题内容",choices = ('按键[<F1>]内容','按键[<F2>]内容')):
  3.     e.msgbox("你选择了按键F1的内容")
  4. else:
  5.     e.msgbox("你选择了按键F2的内容")
复制代码


疑问:为什么快捷键a,b将[]换成[<>]后,字母隐藏且无法正常使用快捷键,而F1 F2则使用[<>]可以正常激活快捷键【代码1为正确代码,2,3为个人想法更变测试】
最佳答案
2020-11-21 22:58:04
看这:https://fishc.com.cn/forum.php?m ... peid%26typeid%3D403

ccbox(msg='Shall I continue?', title=' ', choices=('C[o]ntinue', 'C[a]ncel'), image=None, default_choice='C[o]ntinue', cancel_choice='C[a]ncel')

ccbox() 提供一个选择:“C[o]ntinue” 或者 “C[a]ncel”,并相应的返回 True 或者 False。

注意:“C[o]ntinue” 中的 [o] 表示快捷键,也就是说当用户在键盘上敲一下 o 字符,就相当于点击了 “C[o]ntinue” 按键。

===>模块就这么规定的,你搞这稀奇古怪的干啥,你要有这功夫也可以看看模块的源代码自己去分析

  1. # -----------------------------------------------------------------------
  2. # ccbox
  3. # -----------------------------------------------------------------------


  4. def ccbox(msg="Shall I continue?", title=" ",
  5.           choices=("C[o]ntinue", "C[a]ncel"), image=None,
  6.           default_choice='Continue', cancel_choice='Cancel'):
  7.     """
  8.     Display a msgbox with choices of Continue and Cancel.

  9.     The returned value is calculated this way::

  10.         if the first choice ("Continue") is chosen,
  11.           or if the dialog is cancelled:
  12.             return True
  13.         else:
  14.             return False

  15.     If invoked without a msg argument, displays a generic
  16.     request for a confirmation
  17.     that the user wishes to continue.  So it can be used this way::

  18.         if ccbox():
  19.             pass # continue
  20.         else:
  21.             sys.exit(0)  # exit the program

  22.     :param str msg: the msg to be displayed
  23.     :param str title: the window title
  24.     :param list choices: a list or tuple of the choices to be displayed
  25.     :param str image: Filename of image to display
  26.     :param str default_choice: The choice you want highlighted
  27.       when the gui appears
  28.     :param str cancel_choice: If the user presses the 'X' close,
  29.       which button should be pressed

  30.     :return: True if 'Continue' or dialog is cancelled, False if 'Cancel'
  31.     """
  32.     return boolbox(msg=msg,
  33.                    title=title,
  34.                    choices=choices,
  35.                    image=image,
  36.                    default_choice=default_choice,
  37.                    cancel_choice=cancel_choice)
复制代码
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2020-11-21 17:58:29 | 显示全部楼层
如图
b8965c429c933e1b35147e1f7ba3f01.png
ca45c505d4cd5ef2983418cfc64bdfc.png
50d42dd1f14dc82f96d292c7ec2e657.png
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2020-11-21 22:58:04 | 显示全部楼层    本楼为最佳答案   
看这:https://fishc.com.cn/forum.php?m ... peid%26typeid%3D403

ccbox(msg='Shall I continue?', title=' ', choices=('C[o]ntinue', 'C[a]ncel'), image=None, default_choice='C[o]ntinue', cancel_choice='C[a]ncel')

ccbox() 提供一个选择:“C[o]ntinue” 或者 “C[a]ncel”,并相应的返回 True 或者 False。

注意:“C[o]ntinue” 中的 [o] 表示快捷键,也就是说当用户在键盘上敲一下 o 字符,就相当于点击了 “C[o]ntinue” 按键。

===>模块就这么规定的,你搞这稀奇古怪的干啥,你要有这功夫也可以看看模块的源代码自己去分析

  1. # -----------------------------------------------------------------------
  2. # ccbox
  3. # -----------------------------------------------------------------------


  4. def ccbox(msg="Shall I continue?", title=" ",
  5.           choices=("C[o]ntinue", "C[a]ncel"), image=None,
  6.           default_choice='Continue', cancel_choice='Cancel'):
  7.     """
  8.     Display a msgbox with choices of Continue and Cancel.

  9.     The returned value is calculated this way::

  10.         if the first choice ("Continue") is chosen,
  11.           or if the dialog is cancelled:
  12.             return True
  13.         else:
  14.             return False

  15.     If invoked without a msg argument, displays a generic
  16.     request for a confirmation
  17.     that the user wishes to continue.  So it can be used this way::

  18.         if ccbox():
  19.             pass # continue
  20.         else:
  21.             sys.exit(0)  # exit the program

  22.     :param str msg: the msg to be displayed
  23.     :param str title: the window title
  24.     :param list choices: a list or tuple of the choices to be displayed
  25.     :param str image: Filename of image to display
  26.     :param str default_choice: The choice you want highlighted
  27.       when the gui appears
  28.     :param str cancel_choice: If the user presses the 'X' close,
  29.       which button should be pressed

  30.     :return: True if 'Continue' or dialog is cancelled, False if 'Cancel'
  31.     """
  32.     return boolbox(msg=msg,
  33.                    title=title,
  34.                    choices=choices,
  35.                    image=image,
  36.                    default_choice=default_choice,
  37.                    cancel_choice=cancel_choice)
复制代码
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2020-11-22 15:42:36 | 显示全部楼层
笨鸟学飞 发表于 2020-11-21 22:58
看这:https://fishc.com.cn/forum.php?mod=viewthread&tid=46069&extra=page%3D1%26filter%3Dtypeid%26typ ...

这个是理解的,我只是觉得[<>]符号是设置并隐藏快捷键,[]符号是设置并显示,但是试了一下时而对时而不对
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-5-21 19:46

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表