简体   繁体   中英

How to retrieve and change a value of an attribute of the pack geometry manager?

I'm working on a game where i want the image of the winner to expand its width in an animation so it fills the entire frame at the end. I got the following code to work already, but i need this for some more images and don't want to create a width-variable for each image. Instead i'd like to retrieve its ipadx-value directly and also change it that way.

After Player X wins, I set the anim variable to 1, and the animation gets executed:

# Create Player Info Window:
playerinfowindow=Frame(root, bg='black')
playerinfowindow.pack(side=TOP, fill='both', ipady=3)

playerX=Button(playerinfowindow, bd=0, bg=player[0].color)
iconX=PhotoImage(file='playerX.png')
playerX.config(image=iconX)

width = 84
anim = 0

def px():
    global width
    global anim
    if width < 252:
        width += anim    
    playerX.pack(side=LEFT, ipadx=width)
    playerX.after(10, px)

px()

I want to change the px() function to something like this:

def px():
    global anim
    if playerX['ipadx'] < 252:
        playerX['ipadx'] += anim    
    playerX.pack(side=LEFT, ipadx=84)
    playerX.after(10, px)

pack_info将为您提供该信息。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM