Python, CrossWord, Gui - python-3.x

I am very beginner on Python and I want to create crossworld template, like this. How can I create gui exactly like this on python ? Are there any tools or libraries ? I made lots of research but ı could not find anything.
Thanks!!!

Since you're a beginner, try out PySimpleGUI.
Here's a little program to get you started...
import sys
if sys.version_info[0] >= 3:
import PySimpleGUI as sg
else:
import PySimpleGUI27 as sg
import random
BOX_SIZE = 25
layout = [
[sg.Text('Crossword Puzzle Using PySimpleGUI'), sg.Text('', key='_OUTPUT_')],
[sg.Graph((800,800), (0,450), (450,0), key='_GRAPH_')],
[sg.Button('Show'), sg.Button('Exit')]
]
window = sg.Window('Window Title').Layout(layout).Finalize()
g = window.FindElement('_GRAPH_')
for row in range(16):
for i in range(16):
if random.randint(0,100) > 10:
g.DrawRectangle((i*BOX_SIZE+5,row*BOX_SIZE+3), (i*BOX_SIZE+BOX_SIZE+5,row*BOX_SIZE+BOX_SIZE+3), line_color='black')
else:
g.DrawRectangle((i*BOX_SIZE+5,row*BOX_SIZE+3), (i*BOX_SIZE+BOX_SIZE+5,row*BOX_SIZE+BOX_SIZE+3), line_color='black', fill_color='black')
g.DrawText('{}'.format(row*6+i+1),(i*BOX_SIZE+10,row*BOX_SIZE+8))
while True: # Event Loop
event, values = window.Read()
print(event, values)
if event is None or event == 'Exit':
break
window.Close()

Related

How to convert user voice input into text and store in the excel sheet?

Dear All,
I wrote a simple program of data entry into excel using python.
But I task is that this manual entry will be performed from user voice input.
Can anybody help me in this regard.
import PySimpleGUI as sg
import pandas as pd
import speech_recognition as sr
# Add some color to the window
sg.theme('Green')
exfile = 'Break Down Report.xlsx'
df = pd.read_excel(exfile)
layout = [ # for input text
[sg.Text('Machines Breakdown Entries Table:')],
[sg.Text('S.No', size=(15,1)), sg.InputText(key='S.No')],
[sg.Text('Fault Desc', size=(15,1)), sg.InputText(key='Fault Desc')],
[sg.Text('Start Time', size=(15,1)), sg.InputText(key='Start Time')],
[sg.Text('End Time', size=(15,1)), sg.InputText(key='End Time')],
[sg.Text('Date', size=(15,1)), sg.InputText(key='Date')],
[sg.Text('Employe Name', size=(15,1)), sg.InputText(key='Employe Name')],
# for buttons
[sg.Button('Speak'), sg.Save(), sg.Button('Clear'), sg.Quit()]
]
# main tool bar Window text
window = sg.Window('Daily Breakdown Report ', layout)
def clear_input():
for key in values:
window[key]('')
return None
while True:
event, values = window.read()
if event == sg.WIN_CLOSED or event == 'Quit':
break
if event == 'Clear':
clear_input()
if event == 'Save':
df = df.append(values, ignore_index=True)
df.to_excel(exfile, index=False)
sg.popup('Data saved!')
clear_input()
window.close()
I want to develop a program in Python that performs voice activity in an excel sheet, similar to Google Docs.
According to above code. Manual entries will be performed by the user typing. But i want create a voice button in which user will command by voice and input should store into text and save in excel sheet.
Using thread to do the conversion, like the method window.perform_long_operation.
Demo Code
import speech_recognition as sr
import PySimpleGUI as sg
def speak():
while True:
r = sr.Recognizer()
text = '~ Not recongnized ~'
with sr.Microphone() as source:
audio = r.listen(source)
try:
text = r.recognize_google(audio,language="en-IN")
except:
pass
return text
layout = [
[sg.Multiline(size=(80, 10), autoscroll=True, key='-ML-')],
[sg.Push(), sg.Button('Speak')],
]
window = sg.Window('Title', layout)
while True:
event, values = window.read()
if event == sg.WIN_CLOSED:
break
elif event == 'Speak':
window['Speak'].update(disabled=True)
window.perform_long_operation(speak, 'Done')
elif event == 'Done':
text = values['Done']
window['Speak'].update(disabled=False)
window['-ML-'].update(text+'\n', append=True)
window.close()

Pysimplegui help, I want to rerun my process over and over

I'm still learning python and I am giving myself a project which I am iterating on. I create some random game selectors using CSV files or text files. So I did some research and made a simple gui using pysimplegui and it works. However I want to rerun the script to select a new game with I hit the reload button and I'm just not finding the information I looking for. Maybe I am overthinking it, or underthinking it.
import random
import csv
import PySimpleGUI as sg
#select Random game from CSV file
with open("Retro Games Spreadsheet! - Games!.csv") as f:
reader = csv.reader(f)
chosen_row = random.choice(list(reader))
f.close()
print(chosen_row)
#Create the layout
layout = [[sg.Text(chosen_row)], sg.Button("Reload")],
# Create the window
window = sg.Window("Select Random Game", layout)
# Create an event loop
while True:
event, values = window.read()
# End program if user closes window or
# reloads with the Reload button
if event == sg.WIN_CLOSED:
break
elif event == "Reload":
window[[sg.Text(chosen_row)]]
window.Refresh()
window.close()
Just update all related elements in your layout.
import random
import csv
import PySimpleGUI as sg
#select Random game from CSV file
with open("Retro Games Spreadsheet! - Games!.csv") as f:
reader = csv.reader(f)
rows = list(reader)
chosen_row = random.choice(rows)
#f.close() it will be auto-closed after with statement
print(chosen_row)
#Create the layout
layout = [[sg.Text(chosen_row, key="-ROW-")], sg.Button("Reload")],
# Create the window
window = sg.Window("Select Random Game", layout)
# Create an event loop
while True:
event, values = window.read()
# End program if user closes window or
# reloads with the Reload button
if event == sg.WIN_CLOSED:
break
elif event == "Reload":
chosen_row = random.choice(rows)
window['-ROW-'].update(chosen_row)
window.close()

Python Auto Click bot not working and I cant figure out why

I made a python 'aimbot' type program that looks for targets in the aim trainer and clicks on them. The problem is it clicks but not on the target and I'm pretty sure I did everything right. Here's the program:
from pyautogui import *
import pyautogui
import time
import keyboard
import random
import win32api, win32con
time.sleep(2)
def click(x,y):
win32api.SetCursorPos((x,y))
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN,0,0)
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP,0,0)
while keyboard.is_pressed('q')== False:
pic = pyautogui.screenshot(region=(0,0,1080,1920))
width, height = pic.size
for x in range(0,width,5):
for y in range(0,height,5):
r,g,b = pic.getpixel((x,y))
if g == 154:
click(x,y)
time.sleep(1)
break

how to make the python program light, which is written to print the text on screen directly without window?

From last few days, I have been working on a program which one part is to show the text directly on the window screen, and also update/change them as per requirement. I have completed this part with Tkinter module in python.
The problem is whenever I run the program it behaves like a heavy program due to which other processes become slow. Also If I tried to do some other process in parallel, the background of the text becomes black, which is absolutely undesirable.as the shown in image
I also want to show some dynamic symbol like loading but the use of two Tkinter widget make it slower. if possible please make it more modular and light.
from tkinter import *
import win32api, win32con, pywintypes
from time import sleep
f=Tk()
var = StringVar()
var.set(' ')
f =Label(textvariable = var, font=('Cooper','60'), fg='blue', bg='white')
f.master.overrideredirect(True)
f.master.geometry("+900+200")
f.master.lift()
f.master.wm_attributes("-topmost", True)
f.master.wm_attributes("-disabled", True)
f.master.wm_attributes("-transparentcolor", "white")
f.pack()
for i in range(10):
sleep(5) # Need this to slow the changes down
var.set(u'[ A ]' if i%2 else u'[ B ]')
f.update_idletasks()
also, want to ask can we do it without using the Tkinter module.so it becomes more light and modular. and dependency will be less.
Here is a code which makes your code responsive and also don't use your cpu too much.
from tkinter import *
import win32api, win32con, pywintypes
import time
f=Tk()
var = StringVar()
var.set(' ')
f =Label(textvariable = var, font=('Cooper','60'), fg='blue', bg='white',bd=0)
f.master.overrideredirect(True)
f.master.geometry("+900+200")
f.master.lift()
f.master.wm_attributes("-topmost", True)
f.master.wm_attributes("-disabled", True)
f.master.wm_attributes("-transparentcolor", "white")
f.pack()
for i in range(10):
f.update()
t = time.time()
while time.time() - t < 5:
f.update()
var.set(u'[ A ]' if i%2 else u'[ B ]')
f.update_idletasks()
f.update()
Here is an image of task manager. Its taking only 15 MB memory and no cpu:

Calling the exit function in Python

import sys
e = input("Do you want to continue?(Enter Y or N)?")
if e == "Y":
sys.exit()
I'm trying to create an exit function that allows the user to exit. Am I using the wrong format or did I mess up the syntax ?
Try this code:
import sys
e = input("Do you want to continue?(Enter Y or N)?")
if e == "Y":
sys.exit()
There was an indentation problem and you were missing a :
Also, I'd like to recommend using this logic also:
import sys
e = input("Do you want to continue?(Enter Y or N)?")
if e.lower() in {'y','yes'}:
sys.exit()
This will provide more flexibility since it will accept Y, y and different versions of yes.

Resources