我为我的程序创建了一个开始按钮以开始刽子手游戏。因此,我还想在我的"开始"之上添加一个标题。按钮。但是,当标题太靠近按钮时,按钮会消失:
from tkinter import *
root = Tk()
root.wm_title("HangMan")
canvas = Canvas(root, height=400, width=800)
canvas.pack()
title = canvas.create_text(400, 100, font=("Times New Roman", 20))
canvas.itemconfig(title, text="WELCOME")
#Creates the pole
def startgame():
b1.destroy()
a = canvas.create_rectangle(550,50,550,350,fill = "black")
b = canvas.create_rectangle(350,50,550,50,fill = "black")
c = canvas.create_rectangle(350,50,350,90,fill = "black")
b1 = Button(canvas, text="Start Game", width=30, height=20, command=startgame)
canvas.create_window(400, 200, window = b1)
def callback():
result = e1.get()
text2 = canvas.create_text(600, 20, anchor = "nw")
canvas.itemconfig(text2, text = "Player Name: " + result)
e1 = Entry(canvas)
b2 = Button(canvas, text="Enter", width=10,command=callback)
canvas.create_window(250, 350, window = e1)
canvas.create_window(400, 350, window = b2)
e1.delete(0,END)
e1.insert(0, "Enter your name")
#Creates man
#d = canvas.create_oval(325, 90, 375, 140, outline = "black") #head
#e = canvas.create_line(350, 140, 350, 230, fill = "black") #neck and torso
#f = canvas.create_line(300, 125, 350, 175, fill = "black") #left arm
#g = canvas.create_line(400, 125, 350, 175, fill = "black") #right arm
#h = canvas.create_line(350, 230, 310, 300, fill = "black") #left leg
#i = canvas.create_line(350, 230, 390, 300, fill = "black") #right leg
root.mainloop()
答案 0 :(得分:0)
没关系,我能够通过取出开始按钮的高度来解决这个问题。很高兴我能够解决:D
b2 = Button(canvas, text="Enter", width=10,command=callback)