2016-11-13 143 views
-1

我寫這個類兩種方法:的Python的Tkinter - Tcl錯誤

import tkinter, random 

class MojaGrafika: 
    def __init__(self): 
     self.canvas = tkinter.Canvas(width=400, height=300) 
     self.canvas.pack() 

    def text(self, text, x, y, farba=None): 
     self.x = x 
     self.y = y 
     self.t = text 
     self.canvas.create_text(self.x, self.y, text=self.t) 

然後我運行它(G = MojaGrafika(),g.text(200,150, 'P', '紅') ) 和這個錯誤來了:

Traceback (most recent call last): 
    File "<pyshell#11>", line 1, in <module> 
    g.text(200, 150, 'P', 'red') 
    File "C:\Users\zuzha\Documents\Cvicenia z programovania 2016\ZS\15.cvicenie.py", line 102, in text 
self.p = self.canvas.create_text(self.x, self.y, text=self.t) 
    File "C:\Users\zuzha\AppData\Local\Programs\Python\Python35-32\lib\tkinter\__init__.py", line 2344, in create_text 
return self._create('text', args, kw) 
    File "C:\Users\zuzha\AppData\Local\Programs\Python\Python35-32\lib\tkinter\__init__.py", line 2320, in _create 
    *(args + self._options(cnf, kw)))) 
_tkinter.TclError: bad screen distance "P" 

有人可以幫我嗎?

感謝

回答

2

(英文)

你聲明的方法與參數

text(text, x, y, farba) 

但然後調用參數順序錯誤

text(x, y, text, farba) 

看到

g.text(200, 150, 'P', 'red') 

所以create_text()嘗試使用值P作爲x


(波蘭)ZLAkolejnośćargumentów

+1

是最後一句('PL:ZLAkolejnośćargumentów')答案不知何故一部分? –

+0

@BryanOakley是的它回答波蘭語 - 我看到OP在代碼中使用波蘭語單詞。 – furas

+0

是的,我剛剛發現了,謝謝! – Susan