0

I am a newbie with python and I am creating a game just for fun. I tried using turtle with tkinter because I need buttons and turtle graphics. But the button doesn't show on the canvas.

So here's some of my codes:

root = Tk()
root.geometry('1000x1000')
root.title('Cookie Clicker')
canvas = Canvas(root, width = 1000, height = 1000, bg = 'aqua')
canvas.pack()
wn = TurtleScreen(canvas)

wn.register_shape('/storage/emulated/0/Download/cookie.gif')

cookie = RawTurtle(wn)
cookie.shape('/storage/emulated/0/Download/cookie.gif')
cookie.speed(0)

The codes above are the canvas and the turtle graphics and the code below is the button that doesn't show

click_upgrade = Button(root, text = 'improve clicks', command = up_click)

I tried changing the 'root' on the button to 'canvas', and 'wn' but it doesn't work. So please how do I fix this.

  • welcome to stack: `turtle` and `tkinter` are two different modules for `gui` graphical user interfaces (among many other ones too), so you would be using one or the other, but not both together. – D.L Mar 22 '22 at 10:00
  • You haven't call `.pack()` on the button (as you use `.pack()` on `canvas`), so it is invisible. – acw1668 Mar 22 '22 at 10:40
  • D.L you are mistaken, turtle is designed to also run embedded in a tkinter window. Note the use of `RawTurtle` and `TurtleScreen` in the OP's code, that's turtle's tkinter-embedded API. – cdlane Mar 22 '22 at 23:00

0 Answers0