How to reverse the y-axis of the imported image in Tkinter?

后端 未结 3 1494
故里飘歌
故里飘歌 2021-01-18 04:46

For duplicate-markers: I am fully aware that there are some similar questions in matplotlib, such as this one. My question is about

3条回答
  •  一向
    一向 (楼主)
    2021-01-18 04:55

    It seems to me that this would be simple with code like the below:

    import Tkinter
    #Set up a basic canvas
    top = Tkinter.Tk()
    canv = Tkinter.Canvas(top, bg="brown", height=250, width=300)
    
    #Replace with what ever values you want
    x = 50
    y = 50
    
    #Draw the first dot
    line1 = canv.create_line(x, y, x - 2, y - 2, fill="green", width=3)
    #This next line is pretty much all it takes to find the Y inverse
    y = canv.winfo_reqheight() - y
    #Draw the second dot
    line2 = canv.create_line(x, y, x - 2, y - 2, fill="green", width = 3)
    
    canv.pack()
    top.mainloop()
    

    This returns the following:

    Flipped Y axis

    Basically all I did was get the canvas height (250), and subtract the previous Y value (50) from it, which returned the Y inverse (200). Not exactly a built in function, but the actual flipping part was very simple. Hope that was what you were looking for... Good luck!

提交回复
热议问题