Python中新调用出来的窗口frame1不显示文字内容,为什么 5
代码如下:fromtkinterimport*root1=Tk()frame0=Frame(root1)filename=r"C:\Users\53596\Desktop...
代码如下:from tkinter import *
root1 = Tk()
frame0 = Frame(root1)
filename = r"C:\Users\53596\Desktop\xiaomao.gif"
photo = PhotoImage(file = filename)
theLabel = Label(root1,
text = '学java开发\n到开源社区',
justify=LEFT,
image=photo,
compound=CENTER,
font=('黑体',20),
fg="blue"
)
theLabel.pack()
def create():
def main():
def callback():
var.set("早上好!")
root = Tk()
root.title("LIN")
root.geometry("400x450")
frame1 = Frame(root)
frame2 = Frame(root)
var = StringVar()
var.set("小主,早上好!")
textLabel = Label(frame1,textvariable=var,justify=LEFT)
textLabel.pack()
theButton1 = Button(frame2,text="回复",command=callback)
theButton1.grid(row=0,column=0)
theButton2 = Button(frame2,text="退出",bg="black",fg="white",
command=root.destroy)
theButton2.grid(row=0,column=2)
frame1.pack(padx=20,pady=20)
frame2.pack(padx=60,pady=150)
mainloop()
if __name__ == '__main__':
main()
theButton0 = Button(frame0,text="进入",command=create)
theButton0.grid(row=0,column=0)
theButton3 = Button(frame0,text="退出",bg="black",fg="white",
command=root1.destroy)
theButton3.grid(row=0,column=2)
frame0.pack(padx=20,pady=20)
mainloop() 展开
root1 = Tk()
frame0 = Frame(root1)
filename = r"C:\Users\53596\Desktop\xiaomao.gif"
photo = PhotoImage(file = filename)
theLabel = Label(root1,
text = '学java开发\n到开源社区',
justify=LEFT,
image=photo,
compound=CENTER,
font=('黑体',20),
fg="blue"
)
theLabel.pack()
def create():
def main():
def callback():
var.set("早上好!")
root = Tk()
root.title("LIN")
root.geometry("400x450")
frame1 = Frame(root)
frame2 = Frame(root)
var = StringVar()
var.set("小主,早上好!")
textLabel = Label(frame1,textvariable=var,justify=LEFT)
textLabel.pack()
theButton1 = Button(frame2,text="回复",command=callback)
theButton1.grid(row=0,column=0)
theButton2 = Button(frame2,text="退出",bg="black",fg="white",
command=root.destroy)
theButton2.grid(row=0,column=2)
frame1.pack(padx=20,pady=20)
frame2.pack(padx=60,pady=150)
mainloop()
if __name__ == '__main__':
main()
theButton0 = Button(frame0,text="进入",command=create)
theButton0.grid(row=0,column=0)
theButton3 = Button(frame0,text="退出",bg="black",fg="white",
command=root1.destroy)
theButton3.grid(row=0,column=2)
frame0.pack(padx=20,pady=20)
mainloop() 展开
1个回答
展开全部
你好,你将两个root和root1共用一个mainloop了。所以frame1的那个显示出问题了,下面是我修改以后的代码。
from tkinter import *
def create():
var.set("++早上好!")
root1 = Tk()
frame0 = Frame(root1)
filename = r"C:\Users\nxf36039\Desktop\20190116115007169.gif"
photo = PhotoImage(file = filename)
var1 = StringVar()
var1.set("早上好!")
#theLabel = Label(root1, text = '学java开发\n到开源社区', justify=LEFT, image=photo, compound=CENTER, font=('黑体',20), fg="blue" )
theLabel = Label(root1, textvariable =var1, justify=LEFT, image=photo, compound=CENTER, font=('黑体',20), fg="blue" )
theLabel.pack()
mainloop()
def callback():
var.set("早上好!")
def main():
root = Tk()
root.title("LIN")
root.geometry("400x450")
frame1 = Frame(root)
frame1.place(x=100, y=10)
frame2 = Frame(root)
var = StringVar()
var.set("小主,早上好!")
textLabel = Label(frame1,textvariable=var,justify=LEFT)
#textLabel = Label(frame1,text="nihao")
textLabel.pack()
theButton1 = Button(frame1,text="回复",command=callback)
#theButton1.grid(padx=20,pady=20)
theButton2 = Button(frame2,text="退出",bg="black",fg="white",command=root.destroy)
theButton2.grid(padx=40,pady=40)
frame1.pack(padx=20,pady=20)
frame2.pack(padx=60,pady=150)
mainloop()
if __name__ == '__main__':
main()
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询