首先,我是编程新手,目前只是学习基础知识。我正在使用 python 3.7(在 pycharm 中)创建一个“产品选择器”,并希望鼠标单击其中一个产品按钮,然后在下一次鼠标单击时将产品名称粘贴/打印/插入到我的发票系统中。
目前我的代码工作正常,使用“时间”模块在输入之前设置延迟,允许我选择输入的位置(代码第 49 行)。这是我的代码:
我已经尝试过 onMouseUp 或 onDoubleClick 之类的东西(我知道这些不是正确的代码,但你明白了)。
# import statements import modules
from tkinter import * # tkinter helps create GUI's
from pynput.keyboard import Key, Controller as keyboardController # helps
control keyboard functions
from pynput.mouse import Listener, Controller as mouseController # helps
control mouse functions
import time
import pyautogui
# since pynput.mouse and .keyboard have 'Controller' we have to rename them
so
both will work
keyboarad = keyboardController()
mouseclick = mouseController()
# defining some variables
root = Tk()
root.grid()
btn = {}
raw_col = 1
# product lists set into categories
product = [
'product1',
'product 2',
'product 3',
'product 4',
'product 5'
]
def picker(product):
time.sleep(3)
keyboarad.type(product)
time.sleep(.5)
keyboarad.press(Key.tab)
keyboarad.release(Key.tab)
keyboarad.press(Key.tab)
keyboarad.release(Key.tab)
# for each 'item in 'raw' list we want you to create a button
for item in product:
btn[item] = Button(root, text=item, command=lambda x=item: picker(x),
height=1, width=25)
btn[item].grid(column=1, row=raw_col, pady=5, padx=5)
raw_col += 1
mainloop()
目前实际发生的情况是它等待 3 秒然后输入我想要它做的是在下一次点击类型上
任何帮助将不胜感激,不仅仅是让它工作,而且帮助我学习。