Pygame not processing input - input

When Key is pressed on start menu nothing happens
def wait_for_key(self):
wating = True
while wating:
self.clock.tick(FPS)
for event in pg.event.get():
if event.type == pg.QUIT:
wating = False
self.running = False
if event.type == pg.K_SPACE:
wating = False

You are checking for event.type == pg.K_SPACE which is incorrect. What you want to check for is event.type == pg.KEYDOWN. Once you know it's a key down event, then you can check for event.key == pg.K_SPACE.

Related

How do I make this so that way whenever the user says no it will stop or terminate the program? Currently, it's not doing that

def Main():
global more
InitializeReport()
TeamCode()
more = input("Do you have more to enter?")
while (more != "N" or "No" or "n" or "no"):
ProcPlyr()
more = input("Do you have more to enter?")
CalcAvg()
DisplaySummary()
while (more == "N" or more == "No" or more == "n" or more =="no"):
exit()

Pysimplegui and Pygame merge

hi I am trying to merge a pygame program with pysimplegui.
i'm looking for a way of grabbing the downstroke of a keyboard key. at the moment i can only see an upstroke of the key no matter what im doing.
I have sucessfully created pysimplegui programs but this is the first time i'm trying to merge with pygame.
window is setup by
window = sg.Window('UNICHALL V2.0',
Win_layout,
border_depth =20,
resizable = True,
keep_on_top = False,
finalize=True,
return_keyboard_events=True,
use_default_focus=False)
and in my pygame program i use
for event in pygame.event.get():
if event.type == pygame.KEYDOWN:
stop = pygame.time.get_ticks()
delta = stop - start
key = event.key
if key == 27:
sys.exit(1) ...
i can't get these two work in harmony, they either internally loop forever or simply stop the program dead.
Any help appreciated.
If you just need to detect when key pressed and released, try to bind the event '<KeyPress>' and '<KeyRelease>', not set option return_keyboard_events=True of sg.Window.
Example Code
import PySimpleGUI as sg
layout = [
[sg.InputText('', key='-INPUT-')],
[sg.Button('Add Binding'), sg.Button('Remove Binding')],
]
window = sg.Window('Test Program', layout, finalize=True)
while True:
event, values = window.read()
if event == sg.WIN_CLOSED:
break
elif event in ('Press', 'Release'):
e = window.user_bind_event
action = 'pressed' if event == 'Press' else 'released'
print(f'char:{repr(e.char)} | keycode:{e.keycode} | keysym:{e.keysym} | keysym_num:{e.keysym_num} {action}')
elif event == 'Add Binding':
window.bind("<KeyPress>", "Press")
window.bind("<KeyRelease>", "Release")
elif event == 'Remove Binding':
window.TKroot.unbind("<KeyPress>")
window.user_bind_dict.pop("<KeyPress>", None)
window.TKroot.unbind("<KeyRelease>")
window.user_bind_dict.pop("<KeyRelease>", None)
window.close()

Showing a menu badge

Hello any help please I need to configure holidays that can see bubble notification in menu Request to approve in hr officer and in admin not only on manager departement. it inherit from mail_thread I try this : http://ludwiktrammer.github.io/odoo/odoo-count-badge-menu-notification.html and I try with this but I d'ont understand how can I do it :
def _track_subtype(self, init_values):
if 'state' in init_values and self.state == 'validate':
return 'hr_holidays.mt_holidays_approved'
elif 'state' in init_values and self.state == 'validate1':
return 'hr_holidays.mt_holidays_first_validated'
elif 'state' in init_values and self.state == 'confirm':
return 'hr_holidays.mt_holidays_confirmed'
elif 'state' in init_values and self.state == 'refuse':
return 'hr_holidays.mt_holidays_refused'
return super(Holidays, self)._track_subtype(init_values).
I d'ont know how can I do it . actually only manager can see the badge menu in Request To Approve

Why is my test failing with true == true

I am writing an XCTest
in my test i have BOOL stam = true;
and then XCTest(stam == true,#"value is expected to be true");
however, the test is failing and i get this error message
((value == true) is true) failed - value is expected to be true
You typically need to use the Assertion methods in testing frameworks.
Did you try
XCTAssertEqual(stam,true,#"value is expected to be true");

addEventListener: Only one object hits the endded phase

I have a problem with addEventListener "touch". When two or more object are located nearby and activated with one "touch" only one object hits the endded phase.
What I've tried:
function theBall(event)
local ball = event.target.id.id
if event.phase == "began" then
print("began")
display.getCurrentStage():setFocus(event.target)
end
if event.phase == "ended" or event.phase == "cancelled" then
print("ended")
display.getCurrentStage():setFocus(nil)
end
end
invisibleBall[ball]:addEventListener( "touch", theBall)
in simulator output:
began
began
began
ended
You need to do a:
return true
at the end of your function, if not the event propagates to any objects below it. This is by design. Just put that return true before the last end and you will be all taken care of.