带输入功能不会打印任何内容 [英] Function with input prints out nothing

查看:111
本文介绍了带输入功能不会打印任何内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好,所以我试图获取z.ExNote()以将图像(第8个音符)打印到我正在构建的应用程序的活页乐谱页面上.基本上,每个变量都只与放置音符的(x,y)坐标有关. .ExNote()是类Note中的一个函数,该类将Note对象(Num, staff, measure, note, notetype)的5个变量转换为要放置图像的x,y坐标.这整个混乱局面会为您处理4个变量,因此您可以从理论上输入便笺c,d,e,f,g,a,b,它将在谱表的开头将其打印出来,然后您输入的下一个便笺将是下一个位置,恰好是17像素右边等等.

Ok so I'm trying to get z.ExNote() to print out an image (of an 8th note) onto a page of sheet music for an app I'm building. Basically every variable just has to do with the (x,y) coordinates of where the note is to be placed. .ExNote() is a function inside a class Note which translates 5 variables of the Note object (Num, staff, measure, note, notetype) into an x,y coordinate for the image to be placed on. This whole mess takes care of 4 variables for you so you can theoretically input the note c,d,e,f,g,a,b and it will print it out at the beginning of the staff, then the next note you input will be the next position which happens to be 17 pixels to the right and so on.

StaffL = {0: 'nada', 1: '1R', 2: '1L', 3:'2R',
      4: '2L', 5: '3R', 6: '3L', 7: '4R', 8: '4L'}

pygame.display.set_caption("Piano App")

done = False
clock = pygame.time.Clock()

while not done:

    clock.tick(10)

    for event in pygame.event.get(): 
        if event.type == pygame.QUIT: 
            done=True  



screen.fill(white)
DrawGrandStaffAll()
TS(4,4)
notetypeZ = 'Ethnote'
g=0
while g < 8:
    g+=1
    staff = StaffL[g]
    measureZ = 0
    while measureZ<6:
        measureZ += 1
        wnoteZ = 0
        while wnoteZ<8:
            wnoteZ += 1
            noteZ=(input("\n\nWhat note \nc\nd\ne\nf\ng\na\nb\nc2\nd2\n"))
            z = Note(int(wnoteZ), repr(staff), int(measureZ), repr(noteZ), repr(notetypeZ))
            z.ExNote()
            pygame.display.flip()
pygame.quit()

如果我只键入z最终等于(Note(1, '1R', 1, 'c', 'Ethnote'))然后执行z.Exnote(),它就可以工作了(我的笔记被打印到乐谱上).但是,当我这样做时,它是行不通的.我还在单独的窗口中运行了此代码并打印出z,以确保它不是某些技术错误/典型错误,并且输出正是我想要的.因此,问题不在于变量,也不是技术上的错误.我假设错误与输入有关,因为这是手动输入z=Note(1, '1R', 1, 'c', 'Ethnote')和使用此代码构建语句之间唯一的变化.

If I just type in what z ends up being equal to (Note(1, '1R', 1, 'c', 'Ethnote')) and then do z.Exnote(), it works(my note is printed onto the sheet music). But it doesn't work when I do it like this. I also ran this code in a separate window and printed out z to make sure it's not some technical error/typo and the output is exactly what I want it to be. So the problem isn't the variable and it's not some technical error. I'm assuming the error has something to do with the input because that's the only thing that changes between manually inputing z=Note(1, '1R', 1, 'c', 'Ethnote') and using this code to build the statement.

推荐答案

您使用的是Python 2还是3.如果使用的是Python 2,input()会尝试计算您键入的表达式.我相信您想要在这里的raw_input()返回字符串.

Are you using Python 2 or 3. If you use Python 2, input() tries to evaluate the expression you type. raw_input() which I believe you want here returns the string.

这篇关于带输入功能不会打印任何内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆