为什么在父界面也就是外部定义的图片背景可以被运行,但子界面定义的背景图片就运行不了了?
子界面从def Guser(): 开始
import tkinter as tk
from tkinter import ttk
from tkinter import *
from PIL import ImageTk, Image
#连接数据库
import pymysql
conn = pymysql.connect(host='127.0.0.1',
port=3306,
user='root',
password='mysql',
database='xitong',
charset='utf8')
cursor = conn.cursor()# 创建游标
#管理员添加商品
show_shop=tk.Tk()
show_shop.title("管理员操作页面")
show_shop.geometry("700x700+400+20")
image = Image.open("I:\软件工程\网上购物系统\photo\樱桃.gif")
background_image = ImageTk.PhotoImage(image)
background_label = tk.Label(show_shop, image=background_image)
background_label.place(x=0, y=0, relwidth=1, relheight=1)
tk.Label(show_shop, text='商品预览表', font=('SimHei', 24)).place(x=270, y=20)
tk.Label(show_shop, text='商品', font=('KaiTi', 15)).place(x=200, y=410)
tk.Label(show_shop, text='价格', font=('KaiTi', 15)).place(x=200, y=460)
tk.Label(show_shop, text='序号', font=('KaiTi', 13)).place(x=200, y=510)
# 商品输入
sname = tk.Entry(show_shop, font=('FangSong', 15), width=12)
sname.place(x=270, y=410)
# 价格输入
price = tk.Entry(show_shop, font=('FangSong', 15), width=12)
price.place(x=270, y=460)
# 序号输入
snum = tk.Entry(show_shop, font=('FangSong', 15), width=12)
snum.place(x=270, y=510)
def Increase():
shop_name = sname.get()
shop_price = price.get()
shop_snum = snum.get()
sql = "insert into shopping (sname, price,snum) values (%s, %s, %s)"
cursor.execute(sql, (shop_name, shop_price, shop_snum))
conn.commit()
def Delete():
shop_name = sname.get()
sql="delete from shopping where sname=%s"
cursor.execute(sql, (shop_name))
conn.commit()
def Revamp():
shop_name = sname.get()
shop_price = price.get()
shop_snum = snum.get()
#update 表名 set 列名1=列值1,列名2=列值2,... where 条件;
sql='update shopping set sname=%s , price=%s where snum=%s ;'
cursor.execute(sql, (shop_name, shop_price,shop_snum))
conn.commit()
# 创建表格
table_head = ('shop name', 'price', 'shop num')
table_main = ttk.Treeview(show_shop, height=13, show='headings', columns=table_head)
# 设置表头
table_main.heading('shop name', text='商品名字')
table_main.heading('price', text='价格')
table_main.heading('shop num', text='序号')
# 设置位置
table_main.place(x=100, y=80)
# 设置文字对齐
table_main.column('shop name', width=200, anchor='center')
table_main.column('price', width=200, anchor='center')
table_main.column('shop num', width=60, anchor='center')
def Select():
# 清空表格内容
table_main.delete(*table_main.get_children())
# 执行查询语句
sql = "SELECT * FROM shopping"
cursor.execute(sql)
results = cursor.fetchall()
# 将查询结果插入表格
for row in results:
table_main.insert('', 'end', values=row)
def Guser():
guser=tk.Tk()
guser.title("用户管理界面")
guser.geometry('500x600')
image = Image.open("I:\软件工程\背景图片\三月七.gif")
background_image = ImageTk.PhotoImage(image)
background_label = tk.Label(guser, image=background_image)
background_label.place(x=0, y=0, relwidth=1, relheight=1)
# 创建表格
table_head = ('name', 'password', 'mibao')
table_main = ttk.Treeview(guser, height=13, show='headings', columns=table_head)
# 设置表头
table_main.heading('name', text='用户名')
table_main.heading('password', text='密码')
table_main.heading('mibao', text='密保')
# 设置位置
table_main.place(x=50, y=70)
# 设置文字对齐
table_main.column('name', width=135, anchor='center')
table_main.column('password', width=135, anchor='center')
table_main.column('mibao', width=110, anchor='center')
tk.Label(guser, text='注册用户表', font=('SimHei', 24)).place(x=170, y=20)
tk.Label(guser,text='用户名',font=('KaiTi', 15)).place(x=120, y=400)
gu_name = tk.Entry(guser, font=('FangSong', 15), width=12)
gu_name.place(x=220, y=400)
def Delete():
gus_name = gu_name.get()
sql = "delete from user where name=%s"
cursor.execute(sql, (gus_name))
conn.commit()
def Select():
# 清空表格内容
table_main.delete(*table_main.get_children())
# 执行查询语句
sql = "SELECT * FROM user"
cursor.execute(sql)
results = cursor.fetchall()
# 将查询结果插入表格
for row in results:
table_main.insert('', 'end', values=row)
butt_del_gu = tk.Button(guser, text='删除', font=('KaiTi', 15), width=8, command=Delete)
butt_del_gu.place(x=100, y=500)
butt_sel_gu = tk.Button(guser, text='查看', font=('KaiTi', 15), width=8, command=Select)
butt_sel_gu.place(x=320, y=500)
guser.mainloop()
butt_add_sure = tk.Button(show_shop, text='添加', font=('KaiTi', 15), width=8, command=Increase)
butt_add_sure.place(x=100, y=600)
butt_del_sure = tk.Button(show_shop, text='删除', font=('KaiTi', 15), width=8, command=Delete)
butt_del_sure.place(x=250, y=600)
butt_rev_sure = tk.Button(show_shop, text='修改', font=('KaiTi', 15), width=8, command=Revamp)
butt_rev_sure.place(x=400, y=600)
butt_sel_sure = tk.Button(show_shop, text='查看', font=('KaiTi', 15), width=8, command=Select)
butt_sel_sure.place(x=550, y=600)
butt_gu_sure = tk.Button(show_shop, text='管理用户', font=('KaiTi', 15), width=8, command=Guser)
butt_gu_sure.place(x=480, y=460)
show_shop.mainloop()