ここの最初の例からこのコードを取得しましたhttp://zetcode.com/tkinter/drawing/同じファイルにマップを出力するように修正しました。固有のエラーはなく、ループを通過し、すべての if ステートメントにも適切にヒットします。しかし、最終的にキャンバス/フレームには何もありません。誰でも理由を教えてもらえますか?
from tkinter import Tk, Canvas, Frame, BOTH, NW
class Example(Frame):
def __init__(self, parent):
Frame.__init__(self, parent)
self.parent = parent
self.initUI()
def initUI(self):
self.parent.title("Board")
self.pack(fill=BOTH, expand=1)
canvas = Canvas(self)
#The first four parameters are the x,y coordinates of the two bounding points.
#The top-left and the bottom-right.
color = ""
for x in range(10):
for y in range(10):
if type(landMass[x][y]) is Land:
color = "grey"
if type(landMass[x][y]) is Food:
color = "green"
if type(landMass[x][y]) is Water:
color = "blue"
if type(landMass[x][y]) is Shelter:
color = "black"
rec = canvas.create_rectangle(3 + 50 * y, 3 + 50 * x, 53 + 50 * y, 53 + 50 * x , fill=color)
text = canvas.create_text(3 + 50 * y, 3 + 50 * x, anchor=NW, fill="white", text=landMass[x][y].elevation)
def main():
root = Tk()
ex = Example(root)
root.geometry("500x500+500+500")
root.mainloop()
if __name__ == '__main__':
main()