Learn Python animations 🛸

Поделиться
HTML-код
  • Опубликовано: 16 сен 2024
  • Python tkinter animation animations canvas tkinter GUI tutorial
    #Python #tkinter #animation #animations #canvas #GUI #tutorial

Комментарии • 71

  • @BroCodez
    @BroCodez  4 года назад +33

    from tkinter import *
    import time
    WIDTH = 500
    HEIGHT = 500
    xVelocity = 1
    yVelocity = 1
    window = Tk()
    canvas = Canvas(window,width=WIDTH,height=HEIGHT)
    canvas.pack()
    background_photo = PhotoImage(file='space.png')
    background = canvas.create_image(0,0,image=background_photo,anchor=NW)
    photo_image = PhotoImage(file='ufo.png')
    my_image = canvas.create_image(0,0,image=photo_image,anchor=NW)
    image_width = photo_image.width()
    image_height = photo_image.height()
    while True:
    coordinates = canvas.coords(my_image)
    print(coordinates)
    if(coordinates[0]>=(WIDTH-image_width) or coordinates[0]=(HEIGHT-image_height) or coordinates[1]

    • @Amir_Plays_non_stop
      @Amir_Plays_non_stop 3 года назад

      @datrix North West it is used to place the object at the north west of the window

    • @josephdallinplania7536
      @josephdallinplania7536 2 года назад

      What's the version of the Python that you used here? Mine is Python 2.7 and I cannot display the png images, only gif images

    • @kofe5336
      @kofe5336 2 года назад

      0

  • @murat1696
    @murat1696 Месяц назад +1

    you are the best. You are putting the best efforts possible in your videos. And Also The best phyton are yours.👑👑👑

  • @emmanuelpoirier4602
    @emmanuelpoirier4602 2 года назад +6

    Hey bro,
    Great anim. Please add double buffer to prevent screen tearing and also synchronizes refresh with vertical blank line / end of screen refresh. That will make the result smoother.
    You can also alter the spaceship sprite by inverting it horizontally and vertically according to the bump so the anim is more interesting. And scroll the background to get the whole show more realistic.
    When you combine both realism with fantasy that creates a contrast which makes things far more fun and interesting.
    Thanks for the tutorial.

  • @ibehmiracle4011
    @ibehmiracle4011 9 месяцев назад +1

    You're my best online tutor

  • @bodaciouschad
    @bodaciouschad Год назад +1

    This- now THIS is what I was looking for. *chef's kiss*
    many thanks; I wanted to emulate sprites with tkinter, and I assume I should be able to create buttons with images from here...

  • @lucyledezma709
    @lucyledezma709 4 года назад +4

    Hey Bro!!. So much time!!! Great Video!!!!

  • @sleshkatgcmc1382
    @sleshkatgcmc1382 2 года назад +1

    Thank you for this tutorial, I am a new user of python, and I use different elements that I just learned and combine them together. Your tutorial helped me to create a little code that make a face animation.

  • @OllyCybSec
    @OllyCybSec 4 месяца назад

    This was so Kool learning how to Animate 2D with one image and a different image for the Background‼️🏆

  • @bantuthomas
    @bantuthomas 2 года назад +1

    Great tutorial. Keep it coming.

  • @nvlprod9958
    @nvlprod9958 Год назад +1

    Bonjour vidéo très bien tournée merci !

  • @SmokyDesperado91
    @SmokyDesperado91 11 месяцев назад +1

    Great tutorial thanks a lot!
    Is it possible to store the created animation, e.g. in gif or mp4 format?

    • @mohamedabdibarre7094
      @mohamedabdibarre7094 10 месяцев назад

      yes, simply use screen recorder such as Fast Stone Capture eeeeeeeeeee thaaat is ma opinion

  • @lw9954
    @lw9954 2 года назад +1

    Ty bro!

  • @kbmangang
    @kbmangang 3 года назад +2

    very interesting, I want to learn animation of graph plotting

    • @batmanishere4153
      @batmanishere4153 3 года назад +2

      Then I would suggest you to watch matplotlib tutorials

  • @cristiucvladimir7909
    @cristiucvladimir7909 4 месяца назад

    Thanks.

  • @shubhamalhat2011
    @shubhamalhat2011 7 месяцев назад

    thanks for helping us.. BRO...!!!

  • @mrrohan6396
    @mrrohan6396 3 года назад +2

    Hi , can we create an animation for elevator door open and close using python. is it possible?

  • @veggiet2009
    @veggiet2009 3 года назад +1

    Another way to reverse the motion is to write xV *= -1

  • @derpfisti2457
    @derpfisti2457 Год назад +1

    step 3 = done
    step 1 = done 👍
    step 2 = done 🗯
    thats how screensavers were born. Thanks Bro!!!

  • @fraionhyudz7053
    @fraionhyudz7053 Год назад +1

    Hello Bro. Can I ask if animations also works on buttons?

  • @kapibara2440
    @kapibara2440 8 месяцев назад

    Fantastic!!!

  • @sangitakumari5482
    @sangitakumari5482 2 года назад

    Life saver video!

  • @airlanggak5391
    @airlanggak5391 3 года назад

    so cool!

  • @Poporoporancio
    @Poporoporancio Год назад +1

    I wish this tutorial was more complete because I spent like 2 hours trying to figure out how to insert the image as a file in pycharm, and then it still didn't work, until I figured out that it doesn't work with jpg for some reason, until I decided to use PNG, why? I don't know, I just started Python yesterday

    • @tomaszzdziarski9591
      @tomaszzdziarski9591 Год назад +2

      Try inserting jpg but also png files with: space_image = ImageTk.PhotoImage(Image.open("space.jpg")) and then open it normally in canvas with: my_space_image = canvas.create_image(0,0,image=space_image, anchor = NW)

  • @dineshgautam7027
    @dineshgautam7027 2 года назад

    Great.....

  • @ManhPham-qh2te
    @ManhPham-qh2te 3 года назад +2

    hey Bro. when i swap the position of 2 lines: canvas.move and if conditions, the image can't bounce back when it reaches the right border and keep sticking that way and moving down 'till it reaches the bottom border. Can you explain that for me

    • @MLRTrytonix13
      @MLRTrytonix13 Год назад

      If you listened closely, he said why. The conditions need to be before otherwise the image won't bounce back. Stop conditions are always at the beggining of a while loop so when we reenter the loop, we can verify the conditions.

  • @ctorres1992
    @ctorres1992 2 года назад

    Thank you so much for this tutorial, can anyone help how to send this to a friend so they can see my progression with coding?

  • @ibehmiracle4011
    @ibehmiracle4011 9 месяцев назад

    Bro code, thanks so much for your help.

  • @shahzodsayfiddinov9510
    @shahzodsayfiddinov9510 3 года назад

    Thank you Bro!

  • @HunaBopa
    @HunaBopa Год назад

    I am curious to know how you learned all that you learned about Python

  • @lochito9384
    @lochito9384 3 года назад +2

    How did you put the image in a file?

    • @muradarif7373
      @muradarif7373 2 года назад

      its actually dark for me too, it would be perfect if he showed everything step by step

  • @6figguh
    @6figguh 9 месяцев назад

    So this is the code DSTV used for their old decoders

  • @tomislava741
    @tomislava741 5 месяцев назад

    my background image is not showing how can i solve this problem?

  • @Amir_Plays_non_stop
    @Amir_Plays_non_stop 3 года назад +2

    How can we fix the error when we close the stop the application? I tried to catch it using try and catch but didn't work.

    • @davidcalebpaterson7101
      @davidcalebpaterson7101 3 года назад +3

      That error won't show up in the practice since the force stop we have access from console only, you can simply add a key bind with the .quit method function. to be able to close the app without pressing stop in console. hope that helps.

    • @Amir_Plays_non_stop
      @Amir_Plays_non_stop 3 года назад +1

      @@davidcalebpaterson7101 thanks alot bro!

    • @davidcalebpaterson7101
      @davidcalebpaterson7101 3 года назад +2

      @@Amir_Plays_non_stop my pleasure to help, I am learning a lot whith these videos, very useful channel I am finding similar channels here and there but this one has helped me the most so far.

    • @tomaszzdziarski9591
      @tomaszzdziarski9591 Год назад

      I found other solution on web: This error is caused by close button on top-right corner of window, the only way you have to stop script. After you click close button, window is destroyed, so no widget, like canvas, exist. You can set a flag to identify if while loop should stop and exit in handler of window close button event. Translating from aliens to human language: add def handler():
      global run
      run = False
      window.protocol("WM_DELETE_WINDOW", handler)
      run = True
      while run :
      (yours while loop content here)
      window.destroy()
      window.mainloop()
      change in code True for: while run : and before closing a window.mainloop() insert closing a window with: window.destroy()

  • @eklavyajaret8772
    @eklavyajaret8772 2 года назад +3

    bro but what about images

  • @beingzero7541
    @beingzero7541 2 года назад

    Wow!!!

  • @hamzazad5258
    @hamzazad5258 5 месяцев назад

    when i place my image on the 0,0 coordinates i find it in the center of the canvas i dont how to solve that...this one did not work for me. i literally copied and pasted his code n same problm occured

  • @blexbottt5119
    @blexbottt5119 Год назад

    8:51 have a problem bro, in coordinates[0],
    "cannot find reference"[" in 'None'

  • @davidcalebpaterson7101
    @davidcalebpaterson7101 3 года назад +3

    I have a question, xvelocity and yvelocity appear to be in this code just simple variables so I don't get why they worked at all unless they are specific keywords inside python and therefore understood. That is confusing me since they don't seem to be linked to a function or defined piece of logic to perform that action or at least it seems so. for example if I call them something else like my_variable how in the world they are understood. Please send help I'm stuck there.
    Edit: I understood now cause canvas .move is expecting int coordinates as parameters. Wow. hope that helps someone else too.

    • @LuqeMax
      @LuqeMax 2 года назад

      Then they are not a keywords yeah??

  • @markhagerman3072
    @markhagerman3072 3 года назад +2

    Am I right that the mainloop function never gets used in this program?

    • @exg421
      @exg421 3 года назад

      it does

  • @buggopuggo3306
    @buggopuggo3306 3 года назад +1

    how do you get the image transparent??

    • @davidcalebpaterson7101
      @davidcalebpaterson7101 3 года назад +1

      There are ready ones on the internet but you can create your own in a photo editor to remove backgrounds manually. Or if you meant a transparency efect you can do that as well in Photoshop for example.

    • @piggyplayer07
      @piggyplayer07 2 года назад

      remove.bg

  • @jhassee
    @jhassee Год назад

    oh hell yeah

  • @LuqeMax
    @LuqeMax 2 года назад

    What if I smallize the letter v in xvelocity

  • @LuqeMax
    @LuqeMax 2 года назад

    Is move() a keywors or its a variable
    Because its not defined

    • @lordsubl1me
      @lordsubl1me Год назад

      its a class method, canvas is a class that derived from the tkinter properties.

  • @trickswithandro749
    @trickswithandro749 3 года назад

    i perform all the three steps :)

  • @htetmin1220
    @htetmin1220 3 года назад

    how can i get your images bro

  • @otpreet
    @otpreet 4 года назад

    Don’t give up

    • @BroCodez
      @BroCodez  4 года назад +1

      I'm still determined, don't worry

    • @otpreet
      @otpreet 4 года назад +1

      Bro Code imma sub

  • @turtleeatplastic2386
    @turtleeatplastic2386 3 года назад

    it just like dvd

  • @muralikrishna1785
    @muralikrishna1785 Год назад

    hey Bro... does PhotoImage support jpg format?

  • @andriikorniienko4239
    @andriikorniienko4239 Год назад

    okay, i did this program, and I already feel how Google and Apple are wants me to work with them😎😂😂😂

  • @xiaoduhu5570
    @xiaoduhu5570 3 года назад

    Tried to realise your demo, but...it seems tkinter can't show .png with RGB-A with alpha channel.. how do you achieve that, the little ufo.png without background color?!