[英]how do i get put a text after a button is pressed on a different window tkinter
I tried to put the text in the function itself it didn't say i was wrong but the program didn't show the text does anyone know how to solve this?我试图将文本放在函数本身中它没有说我错了但是程序没有显示文本有谁知道如何解决这个问题?
import tkinter as tk
def life1():
newwindow = tk.Toplevel(root)
app.title("my biography")
texto = Label(root, text ="hello")
root = tk.Tk()
button1 = tk.Button(app,text="my life",command=life1 , padx = 80, pady = 10, bg = "green")
You must call pack
, place
, or grid
on the texto
label.您必须在
texto
标签上调用pack
、 place
或grid
。 If you want the label to show up in the new Toplevel
window, the label needs to be a child of that window (eg: Label(newwindow, ...)
).如果您希望标签显示在新的
Toplevel
窗口中,则标签需要是该窗口的子窗口(例如: Label(newwindow, ...)
)。
First of all, you have to add root.mainloop() at the end to stop the program, otherwise your program window would hang.首先,您必须在末尾添加root.mainloop()以停止程序,否则您的程序窗口将挂起。
Second , to display the text you have to use variable.pack() so that it displays on the window.其次,要显示文本,您必须使用variable.pack()以便它显示在窗口上。
The third and most important thing that everyone forgets is to capitalise the letter L in tk.label每个人都忘记的第三件也是最重要的事情是将tk.label 中的字母L大写
`import tkinter as tk
root = tk.Tk()
root.title("first window")
def life1():
root2 = tk.Toplevel(root)
root2.title("my biography")
texto = tk.Label(root2, text =" hello ")
texto.pack()
button1 = tk.Button(root,text="my life",command=life1 , padx = 80, pady =
10, bg = "green")
button1.pack()
root.mainloop()
` For further queries kindly email awesomeansh03@gmail.com ` 如需进一步查询,请发送电子邮件至 awesomeansh03@gmail.com
Thank you.谢谢你。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.