I have made my own widget called 'InventorySlot' and I need the widgets within my custom one to be made onto a Canvas instead of using 'grid' or 'pack'.
import tkinter as tk
from tkinter import *
from tkinter.ttk import *
class Main:
def __init__(self):
self.root = Tk()
self.root.geometry('500x500')
self.test = InventorySlot(self.root)
self.test.grid()
class InventorySlot(tk.Frame):
def __init__(self,parent,*args,**kwargs):
tk.Frame.__init__(self,parent)
self.options = {}
self.options.update(kwargs)
self.slot = tk.Label(self,height=3,width=6,text='',relief=SUNKEN,bg='#8b8b8b',bd=4,padx=1,pady=0)
self.canvas = Canvas(self)
self.canvas.create_window(10,10,window=self.slot)
self.canvas.grid()
MainTk = Main()
MainTk.root.mainloop()
All it shows is a blank Canvas
You need to create the label after creating the canvas. The order of creation determines the stacking order (ie: the z-index). The label on s there, it's just behind the canvas.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.