When I use this code
widget.Battery(
format = 'Battery: {percent:2.0%}',
foreground = colors[2],
background = colors[5],
padding = 5
),
it Work completly Fine but when I use this code
widget.CPU(
foreground = colors[2],
background = colors[4],
threshold = 90,
padding = 5
),
at bar it shows Import Error: CPU and it happnes with memory net and all those widgets
these thing i have imported
import os
import re
import socket
import subprocess
from libqtile import *
from libqtile.config import Click, Drag, Group, KeyChord, Key, Match, Screen
from libqtile.command import lazy
from libqtile.lazy import lazy
from libqtile.utils import guess_terminal
from typing import List
from libqtile.widget import *
You need to install all the requirements of each widget.
For example, for the CPU widget you may need the python library called psutil
You have all the information of each widget in http://docs.qtile.org/en/latest/manual/ref/widgets.html#
You need to change this line
from libqtile.widget import *
to
from libqtile import widget
Related
I recently started working on a program in python using Tkinter and now I want to open it from another file.
I have a home page file named HomePage.py that will have a button to open another file, called VirusTotalAPI.py. I didn't find any answers because when I run the program, it opens the VirusTotalAPI.py file, and if I close it the Homepage.py will run, but the button won't work and if I try to close it, it will open the HomePage.py.
#Homepage.py
from tkinter import *
import VirusTotalAPI as vt
Home_Window=Tk()
Home_Window.geometry("980x530")
Home_Window.title("VirusTotal By Carotide")
Home_Window.config(background="grey")
def Window_35_mo() :
vt.Window_35mo
Window_35_mo_open = Button()
Window_35_mo_open.config(text= "Fichier < 35 mo", command= Window_35_mo)
Window_35_mo_open.pack()
Home_Window.mainloop()
The next one is a part from the VirusTotalAPI.py because the file is too long
#VirusTotalAPI.py
import requests
import hashlib
import json
from tkinter import *
from tkinter import filedialog
import HomePage
Window_35mo = Tk()
Window_35mo.geometry("980x530")
Window_35mo.title("VirusTotal By Carotide")
Window_35mo.config(background="grey")
global files
global file_path
def retrieve_API():
API_Value=GetAPIBox.get("1.0","end-1c")
print(API_Value)
GetAPIBox=Text(Window_35mo, height=2, width=10)
GetAPIBox.pack()
API_Button=Button(Window_35mo, height=1, width=10, text="YourAPI",
command=lambda: retrieve_API())
API_Button.pack()
Window_35mo.mainloop()
Thank you in advance.
I tried to import it by different ways like this:
import VirusTotalAPI
Or this:
from VirusTotalAPI import *
I tried to do this too:
from tkinter import *
from VirusTotalAPI import Window_35mo
Home_Window=Tk()
Home_Window.geometry("980x530")
Home_Window.title("VirusTotal By Carotide")
Home_Window.config(background="grey")
#homepage
def winopen35mo() :
Window_35mo
Window_35_mo_open = Button()
Window_35_mo_open.config(text= "Fichier < 35 mo", command= winopen35mo)
Window_35_mo_open.pack()
Home_Window.mainloop()
And it told me this:
ImportError: cannot import name 'Window_35mo' from partially initialized module 'VirusTotalAPI' (most likely due to a circular import)
I finally found how to do it there is the solution :
First we need to import os, subprocess and sys
from tkinter import *
import os
import subprocess
import sys
Then,we declare the file path of the file, for this one it is VirusTotalAPI.py by doing so :
GUI_VirusTotalAPI_Path = 'C:\\Users\\...\\VirusTotalAPI.py'
Now we enter the args, to execute and enter the path name :
args = '"%s" "%s" "%s"' % (sys.executable,
GUI_VirusTotalAPI_Path,
os.path.basename(VirusTotalAPI))
We are almost there, now we create a function to run this using the args we previoulsy used :
def Open_GUI_VirusTotalAPI_35mo() :
proc = subprocess.run(args)
Then another function to destroy the window :
def DestroyHomeWindow() :
Home_Window.destroy
Finally we create the button and "tell" it to execute the command Open_GUI_VirusTotalAPI_35moand at the same time close the window :
Window_35_mo_open = Button()
Window_35_mo_open.config(text= "Fichier < 35 mo", command= lambda:[Home_Window.destroy(),Open_GUI_VirusTotalAPI_35mo()])
Window_35_mo_open.pack()
And this is how I did it, sorry for the poor explanation and my bad english, hope this helped some people.
I am trying to build a program which gets me an enlarged photo of the text I want, for this I decided to use tkinter, win32gui and pygetwindow modules after taking some tips from already asked problems on stack overflow am having the following problems:
(1)I don't know how to get the hwnd value of the tkinter window which I created.
(2)I can't get hwnd value even if I know how to get it as the window is created after the complete code has run.
So please suggest me solutions to the problem
This is my code:
from tkinter import *
import win32gui
import pygetwindow as gw
#making the tkinter window
root = Tk()
root.title('DaysLeft')
#getting all the windows with their hwnd values
hwnd=gw.getAllWindows()
print(hwnd)
win32gui.SetForegroundWindow(hwnd)
bbox = win32gui.GetWindowRect(hwnd)
img = ImageGrab.grab(bbox)
img.show()
mainloop()
The above code gives error below as expected:.
line 26, in <module>
win32gui.SetForegroundWindow(hwnd)
TypeError: The object is not a PyHANDLE object
You can use PIL for taking a screenshot and win32gui or pygetwindow to get windows location.
Install PIL by saying
pip install Pillow
then your working code would be:
from tkinter import *
from win32gui import FindWindow, GetWindowRect
import pygetwindow as gw
from PIL import ImageGrab
def ss():
win = gw.getWindowsWithTitle('DaysLeft')[0]
winleft = win.left+9
wintop = win.top+38 #change 38 to 7 to not capture the titlebar
winright = win.right-9
winbottom = win.bottom-9
final_rect = (winleft,wintop,winright,winbottom)
img = ImageGrab.grab(final_rect)
img.save('Required Image.png')
#making the tkinter window
root = Tk()
root.title('DaysLeft')
root.after(3000,ss)
root.mainloop()
Why am i subtracting some amount from the pixels? its because, windows has decorations like drop shadow effect to the windows, which are also part of the windows and will be included in the screenshot, so i used this to get rid of those extra pixels.
Or if your still reluctant on using win32gui then, change the function to:
from win32gui import FindWindow, GetWindowRect
from PIL import ImageGrab
......
def ss():
win = FindWindow(None, 'DaysLeft')
rect = GetWindowRect(win)
list_rect = list(rect)
list_frame = [-9, -38, 9, 9] #change -38 to -7 to not capture the titlebar
final_rect = tuple((map(lambda x,y:x-y,list_rect,list_frame))) #subtracting two lists
img = ImageGrab.grab(bbox=final_rect)
img.save('Image.png')
What is after method? It just calls the function after 3000 ms, i.e, 3 seconds. We are basically giving the system some time to build the GUI and capture screenshot.
Hope it helped, do let me know if any errors or doubts.
Cheers
My project said to "Implement the class for the display of the amplitude of the wave file or frequency entered and create the method that will extract a portion of the waveform to display." I am having trouble passing the user input from one file to another without importing the entire file (tried that gave me errors)
Here's some of my main file:
import tkinter as tk
import winsound
from tkinter import *
from tkinter import messagebox
from tkinter import filedialog``
from tkinter import simpledialog
import Create_Account
import Login_file
import Display_Waveform_Amplitude
class audioFrequencyGUI:
#...... (skipping unimportant code)
def Play(self, Hz):
self.play_frequency.config(command = lambda: winsound.Beep(Hz, 500))
#MAIN LOOP
tk.mainloop()
def Display_Waveform(self):
DisplayWindow = Display_Waveform_Amplitude.Display_Waveform_AmplitudeGUI()
DisplayWindow.amplitude_window.wait_window()
Heres Display Waveform File:
import tkinter as tk
from tkinter import*
import numpy as np
import matplotlib.pyplot as plt
class Display_Waveform_AmplitudeGUI:
def __init__(math):
math.amplitude_window = tk.Tk()
math.amplitude_window.title("Amplitude Display")
math.amplitude_window.minsize(width = 500, height = 500)
def plot_graph(math):
time = 1/frequency
x = np.arrange(0, time, 0.1)
y = frequency - 1
plt.title('Amplitude Waveform: Entering Frequencies')
plt.xlabel('Time (seconds)')
plt.ylabel('Amplitude')
plt.plot(x, y)
plt.show()
I know in my code I haven't passed anything because I simply don't know what to do. I've been moving things around and trying out different things for days. I just need to know how to pass the frequency from my main file to another file that contains another class and function. Thank you I appreciate the help!
If files are in same folder
I think you can solve this just importing the class in the main.py file into display file:
from main import audioFrequencyGUI
Now you can use funcs from main.py file inside display.py
#!/usr/bin/env python
# # myGUI7.py # use pywinauto to start Wireshark
# Visual Studio Code is Run as Administrator
import os
import sys
import pywinauto
from pywinauto.application import Application
# which PyQt5 is needed to be imported?
#from PyQt5 import QtCore, QtWidgets
#from PyQt5.QtGui import *
#from PyQt5.QtWidgets import QAbstractSlider
def process_GUI(pname, fname):
# start Wireshark -- it uses Qt5, ergo backend = uia
app = Application(backend="uia").start(r"C:\\Program Files\\Wireshark\\Wireshark.exe ")
if app.SoftwareUpdate.exists(timeout=5):
app.SoftwareUpdate.SkipThisVersion.click()
app.SoftwareUpdate.Wait_Not('visible') #make sure it is closed
##app['The Wireshark Network Analyzer'].print_control_identifiers()
# open any pcapng file
win = app["The Wireshark Network Analyzer"]
win.wait('ready', timeout=5)
win.type_keys('%F{ENTER}') # Alt+F, Enter (it calls "&File->&Open" menu)
app.Dialog2.FilenameEdit.set_edit_text(pname + fname)
app.Dialog2.Open4.click()
win = app[fname]
win.wait('ready', timeout=5)
##win.print_control_identifiers()
# get the Packet list window
PL = win["Packet list"] # it is a TreeView object
# how do I get the POINT in middle of Down arrow of vScroll on PL?
# = = = = = = =
if __name__ == '__main__':
# use path/file of any pcapng that has been saved
path_name = "C:\\H_Paul\\ws\\"
file_name = "ws-aug22a_SOsample.pcapng"
guiReturn = process_GUI(path_name, file_name)
sys.exit(0)
If your goal is to scroll down Packet List, you can use
# workaround for set_focus() failure on uia backend
app_win32 = Application(backend="win32").connect(path=r"wireshark.exe")
app_win32.window(best_match='Qt5QWindowIcon').set_focus()
PL.wheel_mouse_input(wheel_dist=-10) # negative wheel_dist means scroll down
or try PL.type_keys('{VK_DOWN}') to scroll Packet List.
The value of IsScrollPatternAvailable property of Packet List (QTreeView widget) is false, for this reason PL.scroll("down", "line", 1) cause error message "tree "Packet list" is not scrollable". Also inspect.exe doesn't show scrollbar among PacketList's children.
Also, you can try another approach: get bottom right coordinates of the Packet List, subtract (5,5) or other delta from them and click to this point. Something like (this code just demonstrates idea, because sends click to wrong coordinates on latest Wireshark version, which may be a Qt-related problem):
arrow_coords = (PL.rectangle().right - 5, PL.rectangle().bottom - 5)
for i in range(N):
PL.click_input(coords=arrow_coords)
I am Trying to set an image as the background of my Tkinter window and everything I try doesn't seem to work. Here's the code I have:
import random
import Tkinter # note use of caps
from Tkinter import *
from PIL import Image, ImageTk
import os.path
window = Tk()
window.title('Ask If You Dare')
window.configure(background = '#007501')
If you want the background to be an image (without using canvas), use labels:
import random
import Tkinter # note use of caps
from Tkinter import *
from PIL import Image, ImageTk
import os.path
window = Tk()
window.title('Ask If You Dare')
photo=PhotoImage(file="path/to/your/file")
l=Label(window,image=photo)
l.image=photo #just keeping a reference
l.grid()