我正在使用tkinker python并尝试制作一个4位数的锁定屏幕。我试图为每个数字绘制白色方块,我无法弄清楚如何操纵api以获得完美的方块。我做错了什么,我怎么能这样做?这是我的代码
from tkinter import *
class app(Frame):
def __init__(self, master=None):
super().__init__(master)
master.configure(background="#262626")
master.wm_iconbitmap('moth.ico')
master.title("Moth")
master.geometry("800x600")
self.widgets()
self.pack()
def widgets(self):
backGroundCanvas = Canvas(self, bg='#262626', width=800, height=600)
backGroundCanvas.focus_set()
backGroundCanvas.pack()
#create pin
backGroundCanvas.create_rectangle(self, meme=1)
root = Tk()
app = app(master=root)
app.mainloop()
干杯!
答案 0 :(得分:0)
创建一个带有白色填充的方形矩形。 This是一个很好的参考。我删除了对我没有的图标的引用。
from tkinter import *
class app(Frame):
def __init__(self, master=None):
super().__init__(master)
master.configure(background="#262626")
master.title("Moth")
master.geometry("800x600")
self.widgets()
self.pack()
def widgets(self):
backGroundCanvas = Canvas(self, bg='#262626', width=800, height=600)
backGroundCanvas.focus_set()
backGroundCanvas.pack()
#create pin
backGroundCanvas.create_rectangle(100, 100, 200, 200, fill='white')
root = Tk()
app = app(master=root)
app.mainloop()