I am very new to this so please do not judge if my question seems too obvious.
so I am trying to make a game in the python turtle module and I would like to have different buttons for loading and quitting. I have images of these buttons and I am making these images my turtle object by using .addshape() and .shape() methods. The next step for me is to make sure that when I click any of these buttons I get the desired outcome. My issue is that I cannot figure out how to make that happen i.e how can I make my program do the thing when the mouse clicks within a certain image? I have tried using turtle.onclick() method, but I guess I am not able to utilize that either. Any help would be much appreciated.
Related
I'm making a blackjack game using Python, and the GUI with Tkinter.
I have this so far. It doesn't output the cards yet.
Without cards
I have then used this bit of code to try and link the photos to the file:
code, and this is the output:
with cards.
This is where the problems start.
it is really inconsistent. I have to try to open the file several times in order for the game window to actually open.
When it does finally open, it doesn't work properly. When I click the 'hit' button, I can see that the number of cards left in the deck is going down ( top left corner of the screenshots ), but the photos don't change ; they just remain as the ones in the screenshot.
If I spam click the shuffle button, one of them might change to another image, but they mostly remain the same.
If I remove those lines of code linking the images, it works properly and as expected ( first screenshot ). The cards actually change when 'hit' and 'shuffle' are clicked, although its just the name of the card and not the image.
I'm very new to Tkinter, and this is my first program using it. Can someone please suggest any changes/improvements I can make so that the images of the cards change everytime 'hit' and 'shuffle' are clicked, and also explain briefly why its that way? Any and all help will be greatly appreciated.
Thanks a lot
I'm currently making a BTD6 Auto Farmer what this means is that it will farm the game for me and click on the screen and play the game for me and complete the maps and stuff so I can get rewards that do not give me a competitive advantage because the game is single-player.
And to complete this bot I'd have to wait a certain amount of time and then see whenever a button shows up on the screen and to accomplish this I need to make a function that will wait for an image to show up on the screen and if the image shows up the function should press that image and that's all.
I tried many things and couldn't get it to work, here is my code that doesn't work:
def click_image(img):
x = pag.locateCenterOnScreen(img, confidence=config.OPENCV_CONFIDENCE)
pag.click(x)
This didn't work and I'm not surprised because the code creates the variable then tries pressing the variable there is no check or wait and I don't know how to implement that and that's what I'm asking for, that's the answer I'm looking for :)
It seems like you want to perform an asynchronous task, you should look into the python package asyncio.
Well i am creating a utility for my own needs, that being to help improve my reading on the computer. What i need to do is create a tool which can add a colour filter to a section of the screen, as well as add zoom. The first thing was easy to do, i set the attributes to add alpha, topmost and gave a frame a set bg colour.
What i dont know how to do is the zoom. I was thinking of getting a screen capture cut the selected bit apply image transformation then render it in the window. Of course the utility window will also be drawn and obscure the screen capture. I dont know tkinter well enough and i really want to avoid doing GDI work, but if someone has a solution with it i dont mind using it. Clearly referencing GDI, im making it to run on windows.
Optional: Something i have a work around for but would be nice to have is the ability to click through a window, but i doubt i can do that with tkinter.
EDIT: Since im getting negative votes, and i don't know why please help me improve with a comment.
I'm not looking for someone to do the work for me i just want a hint on what might be the right way to do this. With the main problem being how to get a image for whats underneath the Tkinter window so i can process it.
I'm new to programming in python, but I've went through tutorials which taught me how to create click-able images and connecting them to trigger a callback function.
I am trying to write a script which will allow me to click an image, and move onto a new window or "page" of different click-able images.
Is there a way for me to do this using pygtk? I thought about creating classes and using an if else statement to poll through classes I wanted to use, but it hasn't worked for me. Or am I suppose to continuously hide and show buttons and images?
Is there a way to modify the sample code I've been using to accomplish my goal?
http://pygtk.org/pygtk2tutorial/examples/images.py
Any help would be appreciated, thanks!
You can use a GtkNotebook and hide its tabs. Whenever you need to change page, just switch the current page of the GtkNotebook.
I was wondering how I would undo drawing steps in Python/Pygame.
Basically I have made the mouse draw lines, and when I click my undo Rect, I want the screen to revert back to its original state (before mouse was pressed).
Here is my code but it does not work well.
copy=screen.copy()
if undoRect.collidepoint(mx,my) and mb[0]==1:
screen.blit(copy,(0,0))
if mb[0]==1 and omb[0]==1:
draw.line(screen,color,(omx,omy),(mx,my),5)
can someone who knows what I mean please give me ideas on how to make an undo last drawing button?
Thank you.
Ps. I am fairly new to pygame/python so please go a little slowly.
You just need to save the frames when the user interacts with the application.
For example in a demo paint application I wrote with opengl I used a list with 20 elements max and I was updating it when the user started a new action.
If user clicks to the screen, save the current frame to the list. If user stop clicking save the new frame. Then, when you need to go back you just have to take the last element of your list and draw it to the screen.