我正在尝试为工作中的项目构建一个GUI;该GUI的一个要求是它必须为用户提供扫描条形码中包含的重要数据的字段。我捕获每个字段的结果并将其存储到全局变量中,稍后将其保存为CSV。EzText和Text_Input PyGame模块Pip-Git错误&&直接imp.load_source()
由于PyGame 1.9.3似乎没有内置的Text Field模块,我尝试过使用目前可用的第三方系统; “EzText”和“Text_Input”。但是,我在我的机器上安装了这两个软件(我正在运行Windows 7 SP1,64位)时遇到了问题。
下面是上下文的简要说明: 在执行PyVisa(1),PyGame(2),Git(3)32位和cx_Freeze(4)的安装后,我尝试进行pip-install Eztext和Text_Input,因为Ez和TI的GitHub(a(5),b(6))或Pygame(a(7),b(8))页面都没有特殊的安装说明。我从这里(9),这里(10)和这里(11)拿走了这个指令。 蟒-m PIP安装-e的git + https://github.com/ffavela/eztext.git#egg=eztext 蟒-m PIP安装-e的git + https://github.com/Nearoo/pygame-text-input#egg=pygame-text-input
所得两者的尝试输出大约相同(占Github的地址和模块名差): 匹错误1 (12) 点错误2(13)
我一直试图做一个或我正在寻找的类功能的文件。为此,我遵循How to import a module given the full path?的Checked答案。
import time
import sys
import visa # Used for commands later in the GUI.
import os
from pygame.locals import *
import pygame
#import eztext
import imp
foo = imp.load_source('module.eztext','C:/Python27/src/eztext/eztext.py')
foo.Input()
pygame.init()
#... Later on in the code; skipping source commentary and version history
# Declare Global Variables
global serialnum
serialnum = "default" # Init value
#... skip to creation of PyGame object.
gameDisplay = pygame.display.set_mode(1000,750)
#... Later on in the code; the instance of using the function from <eztext.py>
def PopupOne():
intro = True
#... Skip error-trapping segment.
global serialnum
serialnumField = eztext.Input(maxlength=45,color=(255,0,0),prompt='Serial#:')
# Capture Events for this Field.
events = pygame.event.get()
serialnum = serialnumField.update(events)
# Draw and position the Field [indicates preference of Eztext over Text_Input, due to built-in functions]
serialnumField.set_pos(150,200)
serialnumField.draw(gameDisplay)
#... skip ahead to the end of the Method
pygame.display.update()
# End of <PopupOne()>
现在,我上运行看问题---这是从IDLE输出(轻微改动的匿名文件路径):
Warning (from warnings module):
File "C:/Python27/src/eztext/eztext.py", line 2
from pygame.locals import *
RuntimeWarning: Parent module 'module' not found while handling absolute import
Warning (from warnings module):
File "C:/Python27/src/eztext/eztext.py", line 3
import pygame, string
RuntimeWarning: Parent module 'module' not found while handling absolute import
Traceback (most recent call last):
File "Z:\******\Programming\PyGame\pg_sys_master2.py", line 22, in <module>
foo.Input()
File "C:/Python27/src/eztext/eztext.py", line 25, in __init__
['maxlength', '-1'], ['prompt', '\'\''],['focus','False'])
File "C:/Python27/src/eztext/eztext.py", line 13, in __init__
else: exec('self.'+key[0]+' = '+key[1])
File "<string>", line 1, in <module>
error: font not initialized
>>>
我的查询: 有Python 2.7版.13更改为上面链接的67631中提到的方法不再有效?我是否仅限于将内容复制粘贴到主文件中?
因为我还是这么新,所以我不得不编辑这里的链接; [1]:http://pyvisa.readthedocs.io/en/stable/getting.html [2]:https://www.pygame.org/wiki/GettingStarted#Pygame%20Installation [3]:https ://git-scm.com/download/win [4]:https://anthony-tuininga.github.io/cx_Freeze/ [5]:https://github.com/ffavela/eztext [6 ]:https://github.com/Nearoo/pygame-text-input [7]:http://www.pygame.org/project-EzText-920-.html [8]:http:// pygame .org/project-pygame + Text + Input-3013-5031.html –
[9]:https://www.reddit.com/r/Python/comments/2crput/how_to_install_with_pip_directly_from_github/ [10]:https:// stackoverflow.com/questions/11835396/why-egg-foo-when-pip-installing-from-git-repo [11]:https://stackoverflow.com/questi ons/35991403/python-pip-install-gives-command-python-setup-py-egg-info-failed-with-error-c [12]:https://i.stack.imgur.com/H4NTp。 png [13]:https://i.stack.imgur.com/E3QRM.png –
所有的链接应该在帖子中。请[编辑]你的问题。请参阅[格式化帮助](https://stackoverflow.com/help/formatting)。 – phd