root = tk.Tk() root.geometry('400x400') tk.Label(root, text=修改界面.pack() tk.Button(root, text='退出', command=root.quit).pack(padx=50, pady=40) pannel = Label(root) pannel.pack(padx=10, pady=10) canvas = tk.Canvas(root, bg='white', width=200, height=100) # 绘制画布 tk.Label(root, text=相机视频界面!', font=("黑体", 14), width=15, height=1).pack(padx=40, pady=20) canvas.pack(padx=60, pady=50) tk.Button(root, text="点击此处打开视频", command=ship).pack(padx=30, pady=30)#ship是函数 root.mainloop()
结果是,tk.Button(root, text="点击此处打开视频", command=ship).pack(padx=30, pady=30)不能在界面中显示按钮,然后尝试了很多方法没有解决,然后调整显示位置可以显示,无论如何,我不知道为什么,知道老板可以指出,调整后的代码如下图所示。
root = tk.Tk() root.geometry('400x400') tk.Label(root, text=修改界面.pack() tk.Button(root, text="点击此处打开视频", command=ship).pack(padx=30, pady=30)#将button放在这边就 按钮可以显示 tk.Button(root, text='退出', command=root.quit).pack(padx=50, pady=40) pannel = Label(root) pannel.pack(padx=10, pady=10) canvas = tk.Canvas(root, bg='white', width=200, height=100) # 绘制画布 tk.Label(root, text=相机视频界面!', font=("黑体", 14), width=15, height=1).pack(padx=40, pady=20) canvas.pack(padx=60, pady=50) root.mainloop()