how to hide or delete my buttons in Tkinter python?

im making a small game in a canvas with turtle and a menu with tkinter. the game stays in the tkinter window. so far im able to manipulate the canvas when pressing on a button, and to manipulate the tkinter window. but after pressing on the game button i want the 2 buttons to disappear. to hide or to be deleted. i cannot figure out how to do that? could anybody help me with this? this is my code:

import tkinter as tk
from turtle import RawTurtle

root = tk.Tk()
root.geometry("200x200")

canvas = tk.Canvas(master = root, width = 0, height = 0)
canvas.pack()

def testdel():   
    global canvas
    canvas.config(width = 0, height = 0)
    root.geometry("200x200")

def testteken():
    global canvas
    root.geometry("1000x1000")
    canvas.config(width = 100, height = 100)
    t = RawTurtle(canvas)
    t.pencolor("#ff0000") # Red
    t.goto(200, 110)
    t.pendown()
    t.goto(0, 0)
    t.penup()

button1 = tk.Button(master = root, text = "delete", command = testdel).pack(side = tk.LEFT)
button2 = tk.Button(master = root, text = "draw", command = testteken).pack(side = tk.LEFT)

root.mainloop()

update:

i fixed this problem by changing the 'pack' code behind the button to the normal pack-way >> button1.pack() after this theo's solution did work :)



Read more here: https://stackoverflow.com/questions/64404928/how-to-hide-or-delete-my-buttons-in-tkinter-python

Content Attribution

This content was originally published by Wwes at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: