我正在处理我的代码以创建像素的变量。
我正在使用变量pixel_start = 375
,pixel_middle = 724
和pixel_end = 1073
,因为我想一次检查每个变量。
当我尝试这个时:
def GoRight(self):
basex, basey = self.getControl(347 + self.channels_Index).getPosition()
basew = self.getControl(347 + self.channels_Index).getWidth()
# change program controls to display the proper junks
if self.channels_Index != len(self.program_buttons) - 1:
CurrentRow = self.program_buttons[self.programs_Index].control.getX()
CurrentWidth = self.program_buttons[self.programs_Index].control.getWidth()
CurrentX = self.program_buttons[self.programs_Index].control.getX()
print CurrentWidth
#print CurrentX
pixel_start = 375
pixel_middle = 724
pixel_end = 1073
self.move_flag = True
#Check on pixels size between start and end time
if CurrentRow != pixel_end:
if pixel_start == 375:
if int(prog_width) == 2437:
programs_width = 2082
self.getControl(int(prog_id)).setWidth(int(programs_width))
elif int(prog_width) == 2082:
programs_width = 1735
self.getControl(int(prog_id)).setWidth(int(programs_width))
elif int(prog_width) == 1735:
programs_width = 1392
self.getControl(int(prog_id)).setWidth(int(programs_width))
elif int(prog_width) == 1392:
programs_width = 1038
self.getControl(int(prog_id)).setWidth(int(programs_width))
elif int(prog_width) == 1038:
programs_width = 691
self.getControl(int(prog_id)).setWidth(int(programs_width))
if int(prog_width) == 691:
self.programs_Index += 1
self.setFocus(self.program_buttons[self.programs_Index].control)
elif int(prog_width) == 691:
programs_width = 342
self.getControl(int(prog_id)).setWidth(int(programs_width))
elif int(prog_width) == 342:
self.getControl(int(prog_id)).setVisible(False)
self.getControl(int(prog_id)).setPosition(int(pos_X) - 350, int(pos_Y))
elif int(pos_X) == 724:
nextprogram = int(prog_id) + 1
self.getControl(int(nextprogram)).setPosition(1073, int(pos_Y))
self.getControl(int(nextprogram)).setVisible(True)
elif int(pos_X) == 1073:
self.move_flag = True
print "catch this one"
if pixel_middle == 724:
program_button = [elem.control for elem in self.program_buttons]
programs_id = list()
program_width = list()
positions_X = list()
positions_Y = list()
for elem in program_button:
programs_id.append(elem.getId())
positions_X.append(elem.getX())
positions_Y.append(elem.getY())
program_width.append(elem.getWidth())
programs_id = map(str, programs_id)
posX = map(str, positions_X)
posY = map(str, positions_Y)
program_width = map(str, program_width)
for pos_X, pos_Y, prog_id, prog_width in zip(positions_X, positions_Y, programs_id, program_width):
if int(pos_X) == 724:
self.getControl(int(prog_id)).setPosition(375, int(pos_Y))
if self.move_flag == True:
print "catch this two"
if pixel_end == 1073:
program_button = [elem.control for elem in self.program_buttons]
programs_id = list()
program_width = list()
positions_X = list()
positions_Y = list()
for elem in program_button:
programs_id.append(elem.getId())
positions_X.append(elem.getX())
positions_Y.append(elem.getY())
program_width.append(elem.getWidth())
programs_id = map(str, programs_id)
posX = map(str, positions_X)
posY = map(str, positions_Y)
program_width = map(str, program_width)
for pos_X, pos_Y, prog_id, prog_width in zip(positions_X, positions_Y, programs_id, program_width):
if int(pos_X) == 1073:
print "catch this three"
self.getControl(int(prog_id)).setPosition(724, int(pos_Y))
self.channels_row += 1
#print self.channels_row
if self.channels_row <= 7:
pass
#self.move_flag = False
self.move_flag = False
它将在代码上循环,因为它将触发两次。
在pixel_middle
中,你可以看到我正在使用它:
for pos_X, pos_Y, prog_id, prog_width in zip(positions_X, positions_Y, programs_id, program_width):
if int(pos_X) == 724:
self.getControl(int(prog_id)).setPosition(375, int(pos_Y))
在pixel_end
底线:
if self.move_flag == True:
print "catch this two"
if pixel_end == 1073:
...
for pos_X, pos_Y, prog_id, prog_width in zip(positions_X, positions_Y, programs_id, program_width):
if int(pos_X) == 1073:
self.getControl(int(prog_id)).setPosition(724, int(pos_Y))
我正在尝试检查pos_X
数组中的像素是否确实存在,如果它们不存在则转移到下一个变量,例如从pixel_middle
移动并使用{{1相反。当我尝试使用pixel_end
时,我试图阻止代码触发两次,但它没有帮助。
我正在使用if self.move_flag == True
的数组来检查数组中是否存在像素值pos_X
,375
。
你能否告诉我一个例子,我可以用它来检查数组中的像素是否确实存在以及它们是否与724
和pixel_middle
一起使用?
答案 0 :(得分:1)
不太清楚你到底想要做什么。但是如果想要检查数组中是否存在值,则执行以下检查:
如果数组中的值: ....
x = [ 1, 2, 100]
if 2 in x:
print '2 is there'