问题遇到的现象和发生背景
问题相关代码,请勿粘贴截图
'''canvas画布'''
from tkinter import *
import random
class Application(Frame):
def __init__(self,master=None):
super().__init__(master)
self.master=master
self.pack()
self.createWidget()
def createWidget(self):
self.canvas=Canvas(self,width=300,height=200,bg='green')
self.canvas.pack()
#画直线
line=self.canvas.create_line(10,10,30,20,40,50)
#画矩形
rect=self.canvas.create_rectangle(50,50,100,100)
#画椭圆,两对坐标,分别为其外界矩形的左上角和右下角的点
oval=self.canvas.create_oval(50,50,100,100)
global photo
photo=PhotoImage(file='04.gif')
self.canvas.create_image(150,170,image=photo)
Button(self,text='画10个矩形',command=self.draw50Recg).pack(side='left')
def draw50Recg(self):
for i in range(0,10):
x1=random.randrange(int(self.canvas['width'])/2)
y1=random.randrange(int(self.canvas['height'])/2)
x2=x1+random.randrange(int(self.canvas['width'])/2)
y2=y1+random.randrange(int(self.canvas['height'])/2)
self.canvas.create_rectangle(x1,y1,x2,y2)
if __name__ == '__main__':
root = Tk()
root.geometry('400x230+200+300')
app = Application(master=root)
root.mainloop()
运行结果及报错内容
```python
"C:\Program Files\python\python.exe" D:/pythonProject/gui/my08.py
D:\pythonProject\gui\my08.py:32: DeprecationWarning: non-integer arguments to randrange() have been deprecated since Python 3.10 and will be removed in a subsequent version
x1=random.randrange(int(self.canvas['width'])/2)
D:\pythonProject\gui\my08.py:33: DeprecationWarning: non-integer arguments to randrange() have been deprecated since Python 3.10 and will be removed in a subsequent version
y1=random.randrange(int(self.canvas['height'])/2)
D:\pythonProject\gui\my08.py:34: DeprecationWarning: non-integer arguments to randrange() have been deprecated since Python 3.10 and will be removed in a subsequent version
x2=x1+random.randrange(int(self.canvas['width'])/2)
D:\pythonProject\gui\my08.py:35: DeprecationWarning: non-integer arguments to randrange() have been deprecated since Python 3.10 and will be removed in a subsequent version
y2=y1+random.randrange(int(self.canvas['height'])/2)
Process finished with exit code 0
![img](https://img-mid.csdnimg.cn/release/static/image/mid/ask/925390841646119.png "#left")