return 会结束函数。。
写在循环外面
import random
def randomnumber(number,start,end):
data=set()
while len(data)<number:
element=random.randint(start,end)
data.add(element)
return data
data = randomnumber(10, 1, 100)
print(data)
环境咱们还是使用 Python3.8 和 pycharm2021 即可
实现原理
模块
手动安装一下 cv2 模块 ,pip install opencv-python 安装
安装遇到报错,不会安装看我主页置顶文章有。
素材工具
我们需要安装一下 ffmpeg 音视频转码工具
所有素材左侧扫码领取即可
根据描述,您期望的是一个带界面的、可以手动切换的轮播图,但是运行后只输出了一个数字。推测您的代码逻辑出了一些问题。
建议您重新阅读代码,按照下面的步骤进行排错:
1.检查图片路径是否正确,尝试直接打开图片路径查看是否存在相应图片。
建议先编写一个简单的程序,读取并显示一个指定路径的图片,来测试您的图片路径是否正确。
2.检查图片的大小是否超出了canvas的大小。如果超出,图片可能无法正常显示。
建议给canvas设置好合适的大小,然后调整图片大小,使之适合canvas大小或者相应缩小canvas的大小。
建议您逐行地看一下代码,检查是否有语法、拼写等错误,并加上try-except块以捕获异常。如果出错,可以直接通过捕获异常找到出错的地方。
建议您使用下述的代码设置,使程序窗口可以在屏幕中央居中显示:
# Get the resolution of the screen
screen_width = app.winfo_screenwidth()
screen_height = app.winfo_screenheight()
# Calculate the center x and y coordinates
x = (screen_width / 2) - (800 / 2) # 800 is the width of the window
y = (screen_height / 2) - (600 / 2) # 600 is the height of the window
# Set the position of the window to the center of the screen
app.geometry(f'800x600+{int(x)}+{int(y)}')
按照以上方法一步步排查,您应该能够找到出错的地方并将程序运行起来。祝您好运!