[英]Tkinter - Button on new window
I want to add a button in the new window, but I have a doubt about that.我想在新窗口中添加一个按钮,但我对此有疑问。 Do I do this inside the function, like a did with the label or in a space that I have reserved below, just for the buttons?
我是在函数内部执行此操作,就像在标签中执行此操作,还是在我在下方保留的空间中执行此操作,仅用于按钮?
Follows the code below:遵循以下代码:
from tkinter import *
ftela = Tk()
ftela.state("zoomed")
ftela.title("OMNIA v0")
menu = Menu(ftela)
ftela.config(menu=menu)
##-----------------##
## FUNÇÕES/DEF ##
##-----------------##
def new_window():
newWindow = Toplevel()
newWindow.geometry("800x600+275+75")
newWindow.resizable(height=False, width=False)
newWindow = LabelFrame(newWindow, text="sex")
newWindow.place(x=10, y=10, width=675, height=400)
##-----------------##
## LABELS ##
##-----------------##
mylabel = LabelFrame(ftela, text="teste")
mylabel.place(x=10, y=10, width=300, height=150)
l_teste = Label(ftela, text="teste")
l_teste.place(x=15, y=30)
e_teste = Entry(ftela)
e_teste.place(x=100, y=30)
##-----------------##
## SUBMENU ##
##-----------------##
subMenu1=Menu(menu, tearoff=0)
menu.add_cascade(label="Cadastro", menu=subMenu1)
subMenu1.add_command(label="Empresas", command=new_window)
subMenu1.add_command(label="Usuários")
subMenu1.add_separator()
subMenu1.add_command(label="Bancos/Caixas")
subMenu1.add_command(label="Contas")
##-----------------##
## BOTOES ## <<< here **
##-----------------##
bt = Button()
bt.place(x=100, y=100, width=100, height=100)
ftela.mainloop()
Yes, just add the Button
in the same function that creates the new window and specify the newWindow
as its parent.是的,只需在创建新窗口的同一函数中添加
Button
并指定newWindow
作为其父窗口。 (When any widget is created, a parent-child relationship is created. For example, if you place a text label inside a frame, the frame is the "parent" of the label.) (创建任何小部件时,都会创建父子关系。例如,如果将文本标签放置在框架内,则框架是标签的“父级”。)
This would mean doing it something like this:这意味着做这样的事情:
##-----------------##
## FUNÇÕES/DEF ##
##-----------------##
def new_window():
newWindow = Toplevel()
newWindow.geometry("800x600+275+75")
newWindow.resizable(height=False, width=False)
labelFrame = LabelFrame(newWindow, text="sex")
labelFrame.place(x=10, y=10, width=675, height=400)
##-----------------##
## BOTOES ##
##-----------------##
btn = Button(newWindow, text="My Button") # HERE
btn.place(x=100, y=100, width=100, height=100)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.