Pythonにはまったく新しくありません。単にtkinterを使って基本的なゲームを作るだけです。私は私のメインプログラムでタグを使うことはできますが、自分の関数でタグを作成すると無視されます。以下はコードの問題部分です。宇宙人はうまくいく。タグは保存され、使用可能です。しかし、関数内で行を作成する場合、タグをどのように割り当てても、保存されません。私は変数/ itemconfig /の代わりにtag/tags/stringを試しました。bob =/master.bob =Python 3.5のtkinter canvasは、関数内にタグを作成できないようです。
私は考えがありません。
from tkinter import *
import random
master = Tk()
w = Canvas(master, width=600, height=800,bg='black')
w. pack()
bang = 0 #check if there's a shot active
shottag = "1"
alientag = "a"
def control(event):
global bang,shottag
key = event.keycode
if key == 38: #up arrow
if bang<3:
bang=bang+1
shottag=shottag+"1"
xy = w.coords(ship)
w.create_line(xy[0],700,xy[0],730,fill="white",width=3,tag=shottag)
# w.coords(shottag) would produce [] here -- i.e. no coords
shippic = PhotoImage(file = "ship.gif")
ship = w.create_image(300, 750, anchor=CENTER, image=shippic)
aliens = PhotoImage(file = "head.gif")
w.create_image(random.randint(40,560), 40, anchor=CENTER, image=aliens, tag=alientag)
w.after(100,moveals,alientag)
# this tag works fine
master.bind('<Key>',control)
「ダム」の質問でも構いません。私たちはすべてここに学びます。 – GreenHawk1220
あなたはタグが作成されていないと思いますか? –
コードが作成されていないことを知っています。なぜなら、cords()コマンドはそれを見ないし、.find_withtag()やgettags()もしません。 そして私はそれが返品とは関係ないことを知っています。私がそれを作成した直後の機能の中にタグは見られません。 – user7278007