python-3.x

Dragging object along x-axis in pygame

99封情书 提交于 2021-02-17 02:06:04
问题 I want to be able to drag the blue object along the x-axis (black line) using mouse so that it does not move in y-direction. When I try to drag it, nothing happens. Where is the problem? import pygame def initialize(): pygame.init() global height, width height = 600 width = 900 screen = pygame.display.set_mode((width, height)) screen.fill((255, 255, 255)) pygame.draw.line(screen, (0, 0 ,0), (0, height / 2), (width, height / 2), 3) return screen def object(): dragging = False object_1 = pygame

Why Python random is generating the same numbers?

半腔热情 提交于 2021-02-17 02:03:31
问题 I wrote this code for my homework: import random score=[] random.seed(1) for i in range(0,100): score.append(random.randrange(0,21)) for k in range(20, -1, -1): print("Who get %2d score in test? : "%(k), end='') while score.count(k)!=0: j = score.index(k) print("%3s" % (j), end=" ") score.remove(k) score.insert(j,25) print("\n") I ran it on my computer many times and the results were the same. Ironically, in other computers, the results are different from my computer, but also also getting

Running multiple sockets using asyncio in python

烂漫一生 提交于 2021-02-17 01:53:43
问题 Setup: Python 3.7.4 I am trying to create 6 sockets using asyncio listening on different ports. I tried to implement it like this. Code: import asyncio async def client_thread(reader, writer): while True: package_type = await reader.read(100) if not package_type: break if(package_type[0] == 1) : nn_output = get_some_bytes1 elif (package_type[0] == 2) : nn_output = get_some_bytes2 elif (package_type[0] == 3) : nn_output = get_some_bytes3 elif (package_type[0] == 4) : nn_output = get_some

Running multiple sockets using asyncio in python

本秂侑毒 提交于 2021-02-17 01:52:24
问题 Setup: Python 3.7.4 I am trying to create 6 sockets using asyncio listening on different ports. I tried to implement it like this. Code: import asyncio async def client_thread(reader, writer): while True: package_type = await reader.read(100) if not package_type: break if(package_type[0] == 1) : nn_output = get_some_bytes1 elif (package_type[0] == 2) : nn_output = get_some_bytes2 elif (package_type[0] == 3) : nn_output = get_some_bytes3 elif (package_type[0] == 4) : nn_output = get_some

How do I get the Mouse Position on a Pygame Scaled Surface?

社会主义新天地 提交于 2021-02-17 01:50:39
问题 The game I'm making blits everything onto a pygame.surface which is then scaled to the size of the user's display, maintaining aspect ratio, before the surface is then blitted to the main screen. The problem I'm having now, is that when I query the mouse position (because I want to do a hover effect on certain sprites), it's way off where the sprite is but the x and y match the sprite's coords. Is this because I've scaled the surface? And if so, is there a built-in Pygame method for assigning

How do I get the Mouse Position on a Pygame Scaled Surface?

眉间皱痕 提交于 2021-02-17 01:50:05
问题 The game I'm making blits everything onto a pygame.surface which is then scaled to the size of the user's display, maintaining aspect ratio, before the surface is then blitted to the main screen. The problem I'm having now, is that when I query the mouse position (because I want to do a hover effect on certain sprites), it's way off where the sprite is but the x and y match the sprite's coords. Is this because I've scaled the surface? And if so, is there a built-in Pygame method for assigning

How do I get the Mouse Position on a Pygame Scaled Surface?

大兔子大兔子 提交于 2021-02-17 01:48:46
问题 The game I'm making blits everything onto a pygame.surface which is then scaled to the size of the user's display, maintaining aspect ratio, before the surface is then blitted to the main screen. The problem I'm having now, is that when I query the mouse position (because I want to do a hover effect on certain sprites), it's way off where the sprite is but the x and y match the sprite's coords. Is this because I've scaled the surface? And if so, is there a built-in Pygame method for assigning

Python - communicating with subprocess over a socket

时间秒杀一切 提交于 2021-02-16 22:01:08
问题 I am looking to replicate the way programs like Git and Rsync communicate and transfer data over an SSH connection, but in Python. I understand that these programs fork and exec an SSH command that starts a process on the server side and communication is achieved by the parent processing talking to the STDIN and STDOUT of the forked child process. In C I have seen this done by creating a Unix socket pair (s0, s1), forking the process, pointing the stdin/stdout of the forked process to s1 on

Python - communicating with subprocess over a socket

天涯浪子 提交于 2021-02-16 22:00:58
问题 I am looking to replicate the way programs like Git and Rsync communicate and transfer data over an SSH connection, but in Python. I understand that these programs fork and exec an SSH command that starts a process on the server side and communication is achieved by the parent processing talking to the STDIN and STDOUT of the forked child process. In C I have seen this done by creating a Unix socket pair (s0, s1), forking the process, pointing the stdin/stdout of the forked process to s1 on

How to add levels in a game built in python onely with TKINTER? [closed]

ぃ、小莉子 提交于 2021-02-16 21:25:58
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed yesterday . Improve this question I'm working on a memory game that you have to find the position of the red ball,once you move your ball, the red one disappeare, so in order to get more points you had to move as fast as you can, my problem is how to add more levels, for example Level 1 : find