[英]tkinter frames not showing the widgets
from tkinter import *
import tkinter.messagebox
def message():
text='''sfjkasjdfkjasdfjsdjfjsdlfjasd
fjsdkfjksadjfsajdjfl
sdfasdjflsjdlfsldjflsjd'''
tkinter.messagebox.showinfo("showing",text)
def _price_inputs():
win2 = Tk()
win2.title("Transactions for the project Botique")
win2.geometry("1600x800+0+0")
win2.configure(bg="black")
framex = Frame(win2,width=1600,bg="RoyalBlue4",height=100,relief=GROOVE).pack(side=TOP)
frame1 = Frame(win2,width=1000, height=400,bg="white", relief=SUNKEN).pack(side=RIGHT,fill=Y)
frame2 = Frame(win2, width=775,height=100,bg="white", relief=FLAT).pack(side=BOTTOM)
frame3 = Frame(win2,width=600,height=430,bg="gray",relief=FLAT).pack(side=LEFT,fill=X)
#framex == heading
#frame1 == showing the infos
#frame2 == bottom_infos
#frme3 == adding the buttons and widgets
#==++++===========================title=============================
lbl1 = Label(framex,font=("arial", 30, "bold"),bg="powder blue",fg="green",text="Hello this is the title of the page",bd=10,relief=GROOVE).pack(side=TOP)
btn1 = Button(frame1,font=("arial",20,"bold"),bg="powder blue",fg="white",text="click me").pack()
win2.mainloop()
I am trying to create the gui with tkinter.I am using python3.6 I made frames using tkinter and now when i try to add buttons , Labels etc it doesen't show the buttons or Labels in the output screen.我正在尝试使用 tkinter 创建 gui。我正在使用 python3.6 我使用 tkinter 创建框架,现在当我尝试添加按钮、标签等时,它不会在输出屏幕中显示按钮或标签。
And how to i use pack for frames and grid for widgets in that frame using the pack.以及我如何使用包为框架使用包,并使用包为该框架中的小部件使用网格。
You haven't call function in which you have defined properties.您还没有调用已定义属性的函数。 Just call function by adding _price_inputs()
to your code at last:最后只需将_price_inputs()
添加到您的代码中即可调用函数:
from tkinter import *
import tkinter.messagebox
def message():
text='''sfjkasjdfkjasdfjsdjfjsdlfjasd
fjsdkfjksadjfsajdjfl
sdfasdjflsjdlfsldjflsjd'''
tkinter.messagebox.showinfo("showing",text)
def _price_inputs():
win2 = Tk()
win2.title("Transactions for the project Botique")
win2.geometry("1600x800+0+0")
win2.configure(bg="black")
framex = Frame(win2,width=1600,bg="RoyalBlue4",height=100,relief=GROOVE).pack(side=TOP)
frame1 = Frame(win2,width=1000, height=400,bg="white", relief=SUNKEN).pack(side=RIGHT,fill=Y)
frame2 = Frame(win2, width=775,height=100,bg="white", relief=FLAT).pack(side=BOTTOM)
frame3 = Frame(win2,width=600,height=430,bg="gray",relief=FLAT).pack(side=LEFT,fill=X)
#framex == heading
#frame1 == showing the infos
#frame2 == bottom_infos
#frme3 == adding the buttons and widgets
#==++++===========================title=============================
lbl1 = Label(framex,font=("arial", 30, "bold"),bg="powder blue",fg="green",text="Hello this is the title of the page",bd=10,relief=GROOVE).pack(side=TOP)
btn1 = Button(frame1,font=("arial",20,"bold"),bg="powder blue",fg="white",text="click me").pack()
win2.mainloop()
_price_inputs()
You can't see new items, lbl1
and btn1
as they're:你看不到新的项目, lbl1
和btn1
因为他们是:
win2
, not any frames孩子到win2
,没有任何帧frame3
被另一帧frame3
lbl1
and btn1
are children to win2
, because passing None as the first positional argument or by default, the widget's parent is assigned as the Tk instance. lbl1
和btn1
是孩子win2
,因为通过无作为第一个位置参数或默认,小部件的父被指定为Tk的实例。
lbl1
and btn1
are instantiated with parent arguments as None
, because: lbl1
和btn1
被实例化父参数为None
,这是因为:
framex = Frame(win2,width=1600,bg="RoyalBlue4",height=100,relief=GROOVE).pack(side=TOP)
...
frame1 = Frame(win2,width=600,height=430,bg="red",relief=FLAT).pack(side=LEFT,fill=X)
lines are identical to that of:行与以下内容相同:
Frame(win2,width=1600,bg="RoyalBlue4",height=100,relief=GROOVE).pack(side=TOP)
framex = None
...
Frame(win2,width=600,height=430,bg="red",relief=FLAT).pack(side=LEFT,fill=X)
frame1 = None
Because both framex
and frame3
are the return of the method pack
which is always None
.因为framex
和frame3
都是方法pack
的返回,它总是None
。
One could fix this by separating the geometry manager line with the widget instantiation line:可以通过将几何管理器行与小部件实例化行分开来解决此问题:
framex = Frame(win2,width=1600,bg="RoyalBlue4",height=100,relief=GROOVE)
framex.pack(side=TOP)
...
frame1 = Frame(win2,width=600,height=430,bg="red",relief=FLAT)
frame1.pack(side=LEFT,fill=X)
Comment out frame3 line to see that lbl1
and btn1
actually exists:注释掉帧3网上看到lbl1
和btn1
确实存在:
#frame3 = Frame(win2,width=600,height=430,bg="red",relief=FLAT).pack(side=LEFT,fill=X)
from tkinter import *
import tkinter.messagebox
"""def message():
text='''sfjkasjdfkjasdfjsdjfjsdlfjasd
fjsdkfjksadjfsajdjfl
sdfasdjflsjdlfsldjflsjd'''
tkinter.messagebox.showinfo("showing",text)"""
def _price_inputs():
win2 = Tk()
win2.title("Transactions for the project Botique")
win2.geometry("1600x800+0+0")
win2.configure(bg="white")
framex = Frame(win2,width=1600,bg="RoyalBlue4",height=100,relief=GROOVE).pack(side=TOP)
#frame1 = Frame(win2,width=1000, height=400,bg="white", relief=SUNKEN).pack(side=RIGHT,fill=Y)
frame2 = Frame(win2, width=775,height=100,bg="black", relief=FLAT).pack(side=BOTTOM)
frame3 = Frame(win2,width=800,height=450,bg="gray",relief=FLAT).pack(side=LEFT,fill=X)
#framex == heading
#frame1 == showing the infos
#frame2 == bottom_infos
#frme3 == adding the buttons and widgets
#==++++===========================title=============================
lbl1 = Label(framex,font=("arial", 30, "bold"),bg="black",fg="green",text="Hello this is the title of the page",bd=10,relief=GROOVE).pack(side=TOP)
btn1 = Button(frame3,font=("arial",15,"bold"),bd=8,bg="black",fg="white",text="before 60 hrs",relief=GROOVE).pack(side=BOTTOM)
btn2 = Button(frame3,font=("arial",15,"bold"),bd=8,bg="black",fg="white",text="full_stock",relief=GROOVE).pack(side=BOTTOM)
btn3 = Button(frame3,font=("arial",15,"bold"),bd=8,bg="black",fg="white",text="delivery_report",relief=GROOVE).pack(side=BOTTOM)
before = IntVar()
stock_full = IntVar()
delivery_report = IntVar()
btn4 = Button(win2,font=("arial",15,"bold"),bd=8,bg="black",fg="white",text="hello",relief=GROOVE).pack(side=BOTTOM)
'''import Tkinter as tk
import ImageTk
FILENAME = 'image.png'
root = tk.Tk()
canvas = tk.Canvas(root, width=250, height=250)
canvas.pack()
tk_img = ImageTk.PhotoImage(file = FILENAME)
canvas.create_image(125, 125, image=tk_img)
quit_button = tk.Button(root, text = "Quit", command = root.quit, anchor = 'w',
width = 10, activebackground = "#33B5E5")
quit_button_window = canvas.create_window(10, 10, anchor='nw', window=quit_button)
root.mainloop()
'''
win2.mainloop()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.