Py学习  »  Python

无法发现python shell报告的类型错误

Steven Heung • 5 年前 • 1359 次点击  

嗨,我是计算机科学的新手,正在学习编写python代码。下面是我遇到问题的代码部分:

from uagame import Window
from time import sleep
window = Window('hello',300,200)
user = window.input_string('Enter string>',0,0)

x = window.get_width() - window.get_string_width(user)
y = window.get_height() - window.get_font_height(user)
window.draw_string(user_input,x,y)
sleep(2)
window.close()

它总是显示一个类型错误,我不知道原因。我运行过类似的代码,没有问题 错误如下: builtins.typeerror:get_Font_Height()接受1个位置参数,但给出了2个

任何帮助都将不胜感激

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/45530
 
1359 次点击  
文章 [ 2 ]  |  最新文章 5 年前
Prune
Reply   •   1 楼
Prune    6 年前

其他受访者的猜测是正确的: get_font_height 只需要 Window 对象作为参数,并通过正常的调用序列(即窗口是 self 争论)。字体高度返回为 int .

对输入字符串没有任何依赖性;不允许使用该参数,这就是您收到错误消息的原因。只需删除它并调用 window.get_font_height() .

Supermitch
Reply   •   2 楼
Supermitch    6 年前

我想,这是什么意思? window.get_font_height() 是一种不带参数的方法。既然是 window.<method name> ,第一个参数 get_font_height 可能会是 self !所以你要把一个用户传递给那个函数,我猜,这是第二个参数。

查找uagame窗口的文档。获取字体高度并确保使用正确。