I have a kivy window, and I need to rotate a repeating loop"While" in code, but as expected, "While" stops the automatic update of the window, and as a result, locking it.
For example:
--- "loop window" ---
var = 0
while var <= 100:
var += 1
print(var)
--- "end of loop" ---
The problem is that the program has to wait for the loop to finish, and this is locking in the window. I know that in Tkinter has a function Youroot.update(), which updates the window whenever called, I want to know if kivy also owns, or something similar. Please :)
In Kivy, you should not run a loop like that on the main thread, so just run it on another thread (see threading). If you need to make a change to something in the kivy display from that thread, use Clock.schedule_once() to schedule just that bit back on the main thread.
Related
Currently trying to make a alarm clock, but not sure how to return a seperate window that will soon have numbers on it for the time. Thanks. This is what i currently got right now.
#square interface
#adjustable hour/minute/seconds
#choose stopwatch(stops at a certain time)
#choose timer(counts down from timer)
#a start button
Have not tried anything because i don't know what to type
I am trying to edit my game so that when an if statement occurs an image appears, but the if statement only happens when the object hits the wall and the ball bounces off, so the image only appears for the amount of time the if statement is active. I tried to make a delay command but after the if statement occurs it freezes the entire game for the given time.
Does anyone know how to isolate a delay command or make the image stay visible for an extra second after the if statement expires/after the ball hits the wall and bounces off???
Here are the lines of code that has to do with this:
image_set = pygame.display.set_mode()
image = pygame.image.load("image.png")
def image():
image_set.blit(image,(600,90))
if object.left == (COLLISION_RANGE) or object.right == (WINDOWWIDTH COLLISION_RANGE):
DisplayOoface()
Oof.play()
Put the code to "hide" the image into a separate function, Use the Threading package to create a new thread and pass that function in to be executed.
Within the function you can add a delay to the start of the code. When you start the additional thread within the if statement, you will have the delay you need, and then the function can hide the image.
If you do not thread this task, then python simply processes one line of code at a time. By passing off the task of waiting and hiding the image to a secondary thread, your main thread (the game) can continue functioning as needed.
https://docs.python.org/3/library/threading.html
I have a selenium script that automates signing up on a website. During the process, I have driver.implicity_wait(60) BUT there is a segment of code where I have a try/except statement where it tries to click something but if it can't be found, it continues. The issue is that if the element isn't there to be clicked, it waits 60 seconds before doing the except part of code. Is there anyway I can have it not wait the 60 seconds before doing the except part? Here is my code:
if PROXYSTATUS==False:
driver.find_element_by_css_selector("img[title='中国大陆']").click()
else:
try:
driver.find_element_by_css_selector("img[title='中国大陆']").click()
except:
pass
In other words if a proxy is used, a pop up will occasionally display, but sometimes it won't. That's why I need the try/except.
You can use set_page_load_timeout to change the default timeout to a lower value that suits you.
You will still need to wait for some amount of time, otherwise you might simply never click on the element you are looking for, because your script will be faster than the page load.
In the try block u can lower the timeout say 10 by using driver.implicity_wait(10) or even to 0. Place this before the find element statement in the try block. Add a finally block and set this back to 60 driver.implicity_wait(60).
from pywinauto.application import Application
app = Application().Start(cmd_line=u'"path to program" ')
afx = app[u'Afx:01360000:0']
afx.Wait('ready')
afxtoolbar = afx[u'1']
toolbar_button = afxtoolbar.Button(3)
toolbar_button.Click()
window = app.Dialog
window.Wait('ready')
edit = window.Edit4
edit.Click()
app.typekeys ("Success")
So at this point, I've gotten the application to open, the correct window to pop up and also a mouse click on the box that I want to populate with a short string. I cannot for the life of me, figure out how to pass keyboard input to this field. I have read all the docs for PyWinAuto, and nothing is helping...
Basically all I need to do is figure out how to send a string, and then how to send the TAB key six times. I can then finish my program to automate this application.
I am also using Swapy64bit to help. The program uses a win32 backend. I'm using Python 3.6.
Am I not prefixing typekeys correctly? The PyWinAuto documentation leaves much to be desired.
First the correct name of the method is type_keys, but assume you use it correctly.
The reason might be losing focus at the edit control because type_keys tries to set focus automatically. The solution is:
app.type_keys("Success{TAB 6}", set_foreground=True)
I want to write small script with simple GUI using Rscript or littler.
In the example I use gWidget2RGtk2.
For example, helloworld.R
#!/usr/bin/r
library(gWidgets2RGtk2)
W <- gwindow("Window", visible=FALSE)
L <- glabel("Hello World!", container=W)
visible(W) <- TRUE
This works well if it run in a R session, but get an error when it run from shell:
Error in UseMethod(".gwindow") :
no applicable method for '.gwindow' applied to an object of class "NULL"
In the case of graphics, I know that is required X11() before use plot().
Is possible fix this script to allow render widgets from shell?
(I only need run the script on linux machine)
EDIT: This is an example that works well on Linux. (includes suggestions received in the answer and comment.)
#!/usr/bin/r
require(RGtk2) # required for gtkMain()
require(gWidgets2)
options(guiToolkit="RGtk2")
W <- gwindow("Window", visible=FALSE,
handler = function(h, ...) {
gtkMainQuit() # stop main loop when windows is closed.
}
)
L <- glabel("Hello Word!", container=W)
visible(W) <- TRUE
gtkMain() # start main loop to keep the script alive.
Yes, I have done that in the past. You have to make sure you have a GUI event loop running to keep the app alive by waiting.