#user-interfaces
1 messages ยท Page 39 of 1
oh
hello
anyone know if there is a way to view a crash report or an error message when pyqt5 crashes?
TypeError: can only concatenate str (not "method") to str
File "D:\python\lib\site-packages\kivy\lang\builder.py", line 249, in create_handler
return eval(value, idmap), bound_list
File "D:\onedrive\python\socketio\signin.kv", line 153, in <module>
text: "Connected to 'Server: " + self.HOST + ":" + self.PORT + "'"
File "D:\python\lib\site-packages\kivy\lang\builder.py", line 692, in _apply_rule
rctx['ids'])
File "D:\python\lib\site-packages\kivy\lang\builder.py", line 254, in create_handler
cause=tb)
Process finished with exit code 1
;-; cmon i though it would work ;-;
ok tried a new way
################ Connection ##################
def HOST(self):
conn = self.ids.conn
port = 8080
conn.text = f"Connected to 'Server: {socket.gethostbyname(socket.gethostname())}:{port}'"
##############################################
it shows main window but there is 0 text :/
is HOST() called?
################ Connection ##################
def host(self):
conn = self.ids.conn
port = 8080
conn.text = f'Connected to Server: {socket.gethostbyname(socket.gethostname())}:{port}'
##############################################
BoxLayout:
size_hint_y: None
height: 50
canvas.before:
Color:
rgba: (.102,.153,.190, 1)
Rectangle:
size: self.size
pos: self.pos
MainLabel:
id: conn
text: ""
bold: True
size_hint_x: .9
markup: True
spacing: 3
ExitButton:
text: "Disconnect"
bold: True
size_hint_x: .1
@alpine blaze
that doesn't answer the question, unless the answer is No
idk what you mean tho i put it in mainLabel class
i don't the host function called anywhere, MainLabel contains the conn id that host uses, that's good, but no use if host() is not called
error doesnt match those snippets btw
i guess there is no error now, just not the expected result either
which is totally normal if the host function is not called anywhere, the label is not going to be updated
you want to call it after the connection is done, i guess
@alpine blaze i got it working
does subplot2grid not function with pyqt5
@worn viper
from kivy.core.window import Window
Window.size = (500, 300)
Window.borderless = True
but in the next step (I guess) you will want to create your own window title area
with ability to move kivy app window dragging it.
but such a window 'moving' will not be smooth, at least on Linux (it seems due to sdl)
BoxLayout:
cols:1
BoxLayout:
cols:2
Label:
text: "Server 1"
text_size: root.width - 500, root.height - 140
valign: "top"
Button:
pos_hint: {"y":0.9, "x":0.3, "left":1}
size_hint_y: None
size_hint_x: None
halign: "left"
text: "Terminal-1"
font_size: 20
height: 25
width: 120
Button:
pos_hint: {"y":0.9, "x":0.3, "left":1}
size_hint_y: None
size_hint_x: None
halign: "left"
text: "Start"
font_size: 20
height: 25
width: 120
Button:
pos_hint: {"y":0.9, "x":0.3, "left":1}
size_hint_y: None
size_hint_x: None
halign: "left"
text: "Reset"
font_size: 20
height: 25
width: 120
Button:
pos_hint: {"y":0.9, "x":0.3, "left":1}
size_hint_y: None
size_hint_x: None
halign: "left"
text: "Stop"
font_size: 20
height: 25
width: 120```
trying to get my buttons to left with the text but seems to be having none of it ;-;
2 solutions, either make sure the BoxLayout is exactly the width it needs to be, or add a Widget as the last children, that will take all the remaining space and push the previous widget to the left
anyone used pyqt5? im editing on the desktop then pushing it to my git then pulling on to the pi
my issue is the text sizes are different on the pi compared to the pc side
Desktop
Raspberry Pi
also you may notice the tabs are overlapped by the Pause and Refresh Log buttons
not sure how i resolve this issue without making everything look out of place on the desktop side
are you using OS styles? that might be an issue
okay so i tried QApplication::setStyle("windows");
but it didnt seem to do anything
i also tried QApplication::setStyle("fusion");
maybe i haven't set it right
thinking thats not where i should be adding that line
could just add it to your python code
hmm but its c++ and no idea where to add it
solved where to change the style for the app but still hasnt done anything with the sizes
Have you considered manually setting the font size and fontface?
It's probably not even the size that needs to change, just the font face
Some fonts look larger than others at the same size even
have you turned up the scaling setting?
havent touched any scale settings that i can think of
tried changing the font
it changed it pc side so i readjusted then pushed it to the Pi and buttons still overlap
https://github.com/chriskiehl/Gooey just posted in #python-discussion but especially interesting here
im currently looking into kivy as i was hoping to make an app that will work across PC, Rpi, Android
but i cant even get the same scripts to run in pycharm but i probably havent set it up properly
probably yes, have you made sure you use the same python in pycharm as the one you install kivy for? @candid eagle
(can you run the kivy app from command line for a start?)
i don't know how up to date this is, as i don't use pycharm, but maybe this helps?ย https://github.com/kivy/kivy/wiki/Setting-Up-Kivy-with-various-popular-IDE's
that just links to the official website guide which is what ive tried to follow
well, i just installed pycharm trial, and recorded myself starting a new project and running kivy in it, i had to look around a bit so it took a few minutes, but just the time to compress the video, and i'll be able to share it
(obs produces a 100MB file, and i know ffmpeg will convert it to something like 10MB)
i though i had a valid license that they shared to us kivy devs, but apparently that expired in 2015, didn't think it was that far back ๐ never used it
less than 5MB ๐
it's 5mn long, sorry i wasn't really sure how to do things
sorry only just seen this, ive managed to get the example to run
now i gotta try recreate what i did in QT Creator
no worries, i wanted to check how hard it was anyway, but that doesn't seem too bad
this is what ive got to try and do lol
heh, i was actually wondering earlier how hard it would be to create a kivy theme that looks like that
people seems to complain a lot about the default look and feel
i don't really need to take on more projects though i have already too many orphans or neglected ones
๐ฌ
ive been doing this one for over a year in total but ive had a few different versions/attempts at it lol
i barely know what im doing but slowly making progress here and there
This looks cool
Is it going to be used for an actual aquarium or is it just a scenario you came up with?
yeah for my Aquarium
trying to install Kivy Designer but it says Microsoft Visual C++ 14.0 is required, when i click the link it provides it takes me to the visual studio site, i already have VSC installed so im confused as to what i need
cant find the kivy.bat either
kivy designer is deprecated unfortunately @candid eagle
has it been replaced by anything?
Not yet.
But I'm sure itโs only a matter of time. In any case, I would advise to take a closer look at this framework as well
What framework? Sorry I'm a complete beginner to all this so dont know all the jargon etc
@candid eagle I mean kivy framework:)
yeah, don't use designer, it's broken and nobody is working on it
people who learn to use kivy, and especially kvlang seems not to see a lot of need for a designer after a while
(visual studio โ visual studio code btw, and to build cpython extensions, you need visual studio, but outside that, you probably don't)
Hmm does anyone know of a cross platform gui that has a designer? I want to make an app for windows, android, and pi
Wanted a designer so I can try replicating what I have already made with qt
hello
only reason im trying to move away from qt is i had issues with the layout on another os from what i designed it on
i previously used guizero
i wanna make a calculator but buttons doesn't seem to display in the window
what language you using?
python
dur i should have got that frompysimplegui
did you use pysimplegui before?
post your code or a link and if i cant help hopefully someone will see it
brb just gonna grab a bite to eat
import PySimpleGUI as sg
layout = [
[sg.Input(text_color=('Red'),background_color=('Green'),key='input')],
[sg.Button('1',size=(8,4),button_color=('white', '#3c0545')), sg.Button('2',size=(8,4),button_color=('white', '#3c0545')), sg.Button('3',size=(8,4),button_color=('white', '#3c0545')),],
[sg.Button('3',size=(8,4),button_color=('white', '#3c0545')), sg.Button('4',size=(8,4),button_color=('white', '#3c0545')), sg.Button('5',size=(8,4),button_color=('white', '#3c0545')),],
[sg.Button('7',size=(8,4),button_color=('white', '#3c0545')), sg.Button('8',size=(8,4),button_color=('white', '#3c0545')), sg.Button('9',size=(8,4),button_color=('white', '#3c0545')),],
[sg.Button('-',size=(8,4)), sg.Button('=',size=(8,4),key='igual'), sg.Button('+',size=(8,4),key='mas')],
[sg.Button('clear',size=(8,4))]
]
window = sg.Window("just a window name",layout,size=(500,500))
keys= ''
while True:
event, values = window.Read()
if event is None:
break
if event in '123456789':
keys= values['input']
elif event is 'clear':
keys = ''
window.FindElement('input').Update(keys)
uh edit your post and wrap your code with 3 ``` py with another 3 at the end
let's go to pm
think theres rules against that
i don't think pysimplegui has a designer, or that it can easily replicate the previously described interface
but anyway
designers give a false impression of ease
also there are no rules against people pm-ing each others if they agree, the rule is not to pm people without authorisation, or to ask them to help in PM.
no matter
im trying to press on with qt but i know its going to be a headache down the line
especially when i try get my app to android lol
uh, yeah, kivy would certainly be easier for that
anyway, if you want to avoid as much headache as possible, make sure to split clearly between app logic and interface, usually by putting the app logic into a library that can be used separately, and having the interface just call functions or classes from it.
this way you can scrub the interface any time without losing too much work
yeah i plan on doing that on a rewrite as ill be hosting a server on the rpi to store any data and logic, then a client with the gui to read and edit the data stored on the server
thats the plan anyway
anyone know a reliable way to check for losing/gaining focus in pyqt?
focusOutEvent seems to never get called
and event filters dont seem to even receive focus events
nvm fixed
had to call setFocusPolicy with StrongFocus
Does kivy have a tkinter like style?
if you mean the native appearance of widgets, then no, kivy does not have this. The idea is that you create apps that look the same on all platforms.
although of course, you can recreate almost any interface (if you have some skills)
@sudden wraith
Yeah, kivy is pretty different from tkinter in default appearance and customizability of it
hi everyone - is it a good idea to make desktop applications with pyQT? pros/cons?
how's the support for pySimpleGUI?
better to stick to PyQT or should I switch to PySimpleGUI?
Hi all, i start python (as sysadmin and for personnal tests at home). I start on debian with python3 packages on the system (alonside the python2).
I've installed vscode + python plugins (python, pylint, intellisense)
since yesterday i look severals website to guess how to have a nice workflow for first tutos and real work after.
i've seen most speak about scaffold, virtualenv pytest/unittest (?),... i understand virtualenv will be a mandatory as i plan to use gitlab and CI (maybe with a docker runner) to add tests.
but starting with virtualenv, seems that every website/blog/tuto describe a different content, method, tools to mรนanage them .. i'm totally lost ๐
Current state : debian10, from apt packages python v2.7.16 and python3 v3.7.3, added apt packages : some modules like numpy, and python3-virtualenv (pip not installed), + vscode
hello, i'm not sure why that question is in #user-interfaces, did i miss something specific? Unless that's because of the usage of vscode? here is more about using python to build user interfaces.
but it's normal to be a bit lost, that's a lot to process at first, virtualenv is always a good idea, though not really mandatory especially if you already isolate things in docker, but it never really hurts anyway.
if you do python3 (and you should) you can managed them with the venv module of python, or you can still install virtualenv and work with that
but on debian, you have a few more hoops to jump through, as they removed it pip and virtualenv by default, which doesn't make sense to me, but whatever, it's easy to fix
it's nice to use higher level things to manage your venvs, historicaly things like virtualenvwrapper have been used, and can still be used, but more recently tools like pipenv and poetry have appeared to take a broader scope of project management, it's hard to say at this point if they are here to stay, but there is definitely some adoption of them, so they might, i'm not fully converted, and i use a more classical wrapper for my shell, but you can try various ways and see what's best for you, it's a lively space.
@robust marsh
yes i put it because venv can be configurde ion vscode too it seems (dupliacet, again another method ???)
and not sure where to ask ๐
yes suree i'll start with python V3 (hope in the new job they have not keep v2 ...)
for command line only, i juste read a blog speaking about pip freeze > requirements.txt, and in comment many people says : don't do this !
i've seen some speakinf on pyenv, other python setup.py, other cookiecuutle, or pyscaffold ... and seems all those tools designed in the same goal
additional note : i have a gitlab server, and will add a runner for add CI to my projects. seems the better is to have CI runs in docker instances, and then will need the requirements.txt (and dev-requirements.txt)
and for IDE, can you confirm that vscode is a good choice ? i first try pycharm, but too complicated at start , vscode is really more user friendly for now
(python3-virtualenv and python3-pip added on my system via apt)
some of these tools are higher level than others, and build on top of some of the other ones
i would advise to start by understanding (at least on a basic level) what python setup.py does, as it's the most fundamental one in python packaging
seems taht pip is abovce setup.py, or using it at least (i was reading on this ๐ )
yeah, i do have a gitlab as well, i've yet to setup ci again, (did so at previous company), it's really cool
pip is mostly search + download + call setup.py yes
never done still, old job refuse to use git/gitlab/ other tools for devs
ouch
new job : i will manage servers with ansible + python scripts (1st need to learen python ๐ ), and i suggest to manage and versionn all codes/snippets
๐
and will porpose a gitlab (and with a CI for pylint and mayne aother tools i've seen)
a whole SUPER stack to learn !
gitlab-ci, python, docker, ansible !
yeah, i would advise to add things one at a time though, as maintaining them will take you time, and if you added a lot at once, it might quickly get overwhelming
at least, but really many things to understand (as i don't want to try blind "like this and i'll see"
CI is nice to have, but takes a lot of time to get working at first
yes, but seems i'll have not many helps.. the team is essentially windows admins ... they don't have gitlab
(not specific to gitlab, it's always the case as far as i know)
yes ๐ i would start with basics like linter + pep (?), and see tests later
and devs will break your CI when they push bad code, and you'll have to understand why, or have them look at why
i already put a bash linter in gitlab, too wonderfll
for linux part, a whole new team, i'll try to discuss about good practice at the start ...
always too complicated to start "witout" rules and try add them after
i love best practices
hmmmmm mkvirtualenv not in pyhyton3-virtualenv package ...
for the chan, is there a better place to discuss workflow and tools and virtualenv ?
but python3 -m venv should do the trick
ha ok
"my legacy workflow"
he spoke about diffrent workflows in the time
yeah
now using pyenv
as a sysadmin, you should probably frown on the curl | bash call, that's not great security there
better download it, review and then execute
yes ๐
sadly very common
and often working behind proxy/firewall too
and generally take the "latest current" version is not good, because if you try 2 weeks later, maybe another code
i prefer DL, test, and if ok i reproduce
and if newer version .. need to restart all
but at least, same version everywhere
(the same principle than using requirements.txt :)) )
yeah, but then once you have pinned versions in CI, you can update the version in a PR, see if things still work, and then merge
pyenv not packages on debian, and not available in pip ?
read that it's better to stick with packaged version than took on github/gitlab
i guess the author just wants bleeding edge
pip3 search pyenv --> pyevn (0.0.1)
c'est bien pypi.org le repo officiel python ?
github ils sont ร la 1.2.13 du 09/07
oups
on github it's 1.2.13, and pypi.org .. only 0.0.1
hm, apparently no, pyenv only has a placeholder package on pypi, and is not installable through pip, weird
i'm sure it was at some point, not sure why they changed it, but ok, https://github.com/pyenv/pyenv#installation
ok, they should switch repos to gitlab.com ๐
well, i agree that open source is better, but the community is mostly on github, and github is pretty nice, it's hard to make people move
i use github a lot for both work and open source, even if i have a gitlab at home for myself, and used gitlab at my previous job
they says that requirement.rtx file are old-school ๐ now there's a better way ๐
yeah, as i said, things are changing
a lot of existing projects still use requirements.txt though, personally i moved to putting the things as dependencies in setup.py
yes but i will start new projects
is there a way to display a database in a kivy screen, or even anchor db browser on a screen?
Is electron the best language that can be used with Python to create beautiful gui
Electron isn't a language, it's a framework. Also, it's for JavaScript, not Python.
Does anyone here uses PySimpleGui?
In Kivy, is there a way to swap ActionPrevious and ActionButtons/Group positions? So that the buttons are on the left side
@tame spindle i'm pretty sure kivy is better to create beautiful GUI than electron, but it's different, it depends a lot on how familiar you are with web technologies (for electron) and opengl (for kivy).
Thanx @alpine blaze I will definitely try kivy
is there a quick built-in way to clamp a QPoint inside a QRect?
yo
Im using tkinter
Im trying to display an image thats inside a function
however, when the display image code is inside a function it doesnt work
it works fine outside of the function
Any suggestions?
ughhh
when I run all I get is a blank window
w1's lifetime is inside the function only
You have to make w1 avalible outside of the function
hi, some help to configure pylin3 in VSCode please ?
is there a way to inbed a .py file in the screen of another python ap?
so i have a python file i import into my main and then use to query a DB and then great a ui to view the DB
but it opens in a seperate window and im trying to get it to display in the main app
I started creating a text/code editor with kivy. I'm at that point where I can edit the editor with itself 
gonna make the new and better sublime?
suglyme might be a better name for my app... But I plan on working on it long-term
w1 dies when the function ends
Wotttt
Ahh
Hmm
Still donโt get it
and how can I resolve this @tidal spruce ?
@bold gorge hey, nice start ๐
Thanks! Also my first time using kivy ๐
๐ how is it going?
I haven't seen much of the documentation, but it's a bit confusing as to what i should subclass and what to use directly in .kv files
well, the doc might be useful to understand concepts, the we tried to present most aspects of the framework in the programming guide, and the API doc is very useful too (though you can also just have the code and look into it, which is what i prefer when i wonder how something works)
Yeah the API doc is a big time saver ^^
i was all ready to code the syntax highlighting myself and there's this neat CodeInput that already does that
๐
What's the objective of your editor btw? Are you doing it by curiosity, or do you plan features that you think are missing in other editors?
Code highlight is sometime broken because of line cuts if i remember well.
strings going over multiple lines for example
It's just a small project for myself. I thought it was a neat idea being able to develop a simple application with so many capabilities. Hopefully by the time I'm satisfied with it, it will have a lot of features ๐
๐
Yeah it does that, and I also had this weird bug where a line goes invisible unless you change any character
But very happy with the lib overall
Also if anybody is brave enough to work with this smol editor it's open source aswell ^^
you mean using one library with the api of another? why not use the other? or why not learn the api of the first one instead? if these things have a different api and capabilities, there are certainly reasons for it
Kivy: Is there a way to add a custom widget in separate .kv files? Or do I need to do that through code? Something like:
App.kv
# Somehow reference CustomWidget ```
CustomWidget.kv
```<CustomWidget>:
BoxLayout:
...```
Ok figured out there's a directive #:include filename.kv that fixes it ๐
Is anyone here familiar with Bimpy?
anyone uses processing here?
Does anyone have experience with pygobject and glade?
Hi, in a PyQt window which starts maximized, how can a set the width of a widget to be maximized as well? (maximized window -> maximized widget's width)
Hi, how can I only open a PyQt System tray menu on right click but not on left click?
Should there only be one window open at a time?
@thorny spruce I need to make it so there can be multiple windows at a time
Then you should use a tkinter.Toplevel window. You should only ever have one tk.Tk window
What does that do?
It's a widget that's another window
So I just make it root = tk.toplevel?
tk.Tk is your root window (your first one), any other windows you want should be a tk.Toplevel window
For example
import tkinter as tk
root = tk.Tk()
tk.Label(root, text='This is my root window').pack()
for i in range(3):
win = tk.Toplevel(root)
tk.Label(win, text=f'This is window #{i}').pack()
root.mainloop()
I still seem to be having an issue
@thorny spruce I want it to open another window everytime I click p
You can bind your window if that's what you want
How can I do that?
Use the .bind function
hm
Well, I already have events
I just need to make a new window everytime I click p
what's the best widget to display a paragraph of text?
Label works but when packing it, it isn't properly centred
For tkinter? Text widget
Idk what to say really
@thorny spruce isn't Text for editable text?
Yes, you can disable it if you want
Actually I think you can specify the wraplength for a Label
that might work
welp
turns out i was just defining a multiline string incorrectly ๐
it's for qt, and pyqt is just a wrapper around that
it's a method of the class, so call it like a method in python
I get this
But the selection thing works well
I just need to get the values in string format
This gives me
Any way I can get [0.0, 0.5, 0.613] ?
that gets you the list items
Sorry but I don't understand ๐ฆ
you need to call .text or .data on those items to retrieve their values as found here https://doc.qt.io/qt-5/qlistwidgetitem.html
ahh lemme try
qt stores almost everything in items so you can do more things with them
I am still confused
Where do i use .data?
If I am not mistaken, .data takes in int value
you call it on each of the items. The role refers to which value you want to get, as it can store multiple (for display, and an internal for example) There are python docs here but I find them more confusing to navigate through https://doc.qt.io/qtforpython/PySide2/QtWidgets/QListWidgetItem.html
I believe what you want will be at role 0, or you can use the text method
I've been thinking of making a small library that integrates a pandas dataframe with qabstracttablemodel
That should be fine
I think it's just PyCharm getting confused about the types
you could try addng an arg to the lambda
because technically the slot for the clicked signal has a boolean in the parameters
But it will work anyway if that parameter it not present

Okay so I have a QTableView which is populated using a pandas dataframe
And I use a QListWidget called memList to filter the dataframe
The dataframe has a column called memory and I would like to filter the df according to the selection i make in memList
I use this code to filter things out
My code works perfectly for all values except 'nan' and 'All'
What is going wrong?
I need to do the endswith thing cause the values in the dataframe aren't exactly all the same. My memlist has 1.0 GiB but the dataframe has 1 GiB
Hence the conversion
So I am converting all whole numbers like 2048.0 GiB to 2048 GiB to make life easier

Is there a name for the interface I'm thinking of? (command line job status report)
[checkbox] task
[checkbox] task
[checkbox] task
[red mark] task
[checkbox] task
[idler] task
[spinner] task
[spinner] task
Complete: 7/XXX ETA: {ETA}
EDIT: Looks like I can sort-of build this myself using blessings, as long as I keep track of row-number for these jobs.
Perhaps there's already a library that does this? :)
Hi guys.
I am using Kivy and trying to create a program that compares 2 lists. I managed to create it in a fairly reusable way based on this example. https://stackoverflow.com/questions/53834602/kivy-selectable-recycleview-inside-screen-manager
I am using two lists on my design, but I want the buttons on each of the lists to do different things (if you click on the one on the left to do something, if you click on the one on the right something else).
BoxLayout:
orientation: "horizontal"
ListButtonBox:
button_text: "Send to right"
ListButtonBox:
button_text: "Send to left"
Anyone knows how to control each button differently?
just bind to an event?
I have a Qtableview
However a new value is added to it every minute
How do I make my qtableview update every minute?
Hello, I made a simple gui that is able to read text lines from a file.
I would like to be able to display some info about a word when the cursor hovers over it (through a tooltip or similar), is this possible?
can add a tag to sections of text that you can bind enter/leave events to
Using PyQt, what would be the way to make a button that asks for a user input and then stores it as a variable?
preferably using a pushbutton
Guys I have question is there any way to style you own PyQt5 App ? I mean setting a background color or pushbutton color ?
Yes, look up qt style sheets
Ok thanks. It looks very similiar to CSS if it is not the same
Yeah I think that was the idea
Maybe this is simplier than the Kivy style of doing interface
could someone explain how I could use an interface to take in an imput from the user, take that, perform some sort of operation, and ouput something to the user?
you'd need a widget that takes text input
and another widget that can display text
and maybe a button the user presses to signify they are done entering input
QLineEdit and QTextEdit can take text input
QLabel can display text output
You should refer to the documentation on these widgets to learn how to retrieve or set the text for them
And I said before, you'd use signals and slots so you can know when the button has been pressed and you can do whatever operation you want
should I use lineEdit for text edit if I want the user to give me a string?
Depends
QLineEdit takes a single line
QTextEdit supports many lines
like paragraphs
and has more formatting options and so on
Ah so then i need line edit
def onPressed(self):
self.label.setText(self.lineedit.text())
x = str(self.lineedit.text())
print(x)
stockvalue = si.get_live_price(x)
stockvalues.append(stockvalue)
print(stockvalue)
a pyqt5 question:
Code: https://hastebin.com/azevacegis.rb
i want to get rid of the white space under the lineedit, how can i do this?
output:
@versed trout what's wrong with "Kivy style of doing interface"? ๐
@digital rose Well nothing like its just specific language if I remember right
And I didn't do much with Kivy but I think using something similiar to CSS is simplier than something new if you understand. It's just my opinion.
@weary sun From a cursory reading, it looks like you are not using sizers. You really should. They automatically size the element based on available space and you can give it a behaviour to grow or not etc.
I am currently using pygame and I am looking for a UI library to build the game GUI. Glooey was recommended, so long as I migrate to pyglet from pygame - a big ask! I can't find anything about UI for games so not sure how pyqt, tkinter etc. would hold up. Any advice?
QT and tkinter are not suitable
But you can easily use pygame to make a gui
a gui, in the end, is just images that serve as buttons and react on events like mouse over or clicks
or use pyglet
all you need is a renderer and input events to build a gui
Tbh, i've spent two days migrating to pyglet and I am yet to feel any benefit.
I am sure I can create a basic UI but it seems like it can get quite complex, quite fast. And my skills are pretty mediocre.
you are right there, but read the link
there are some readily available gui toolkits available
or stick with pyglet and use glooey
I've read that page a few times and there's only Thorpy still active.
And i've heard a lot of criticism for it.
Though I can give it a go if nothing else jumps out!
Okay, let's take it from this side: What kind of interface do you need?
Lists and complicated stuff? Or just buttons and health bars?
The former. Aspirational would be Pillars of Eternity, but more realisticalll something along the lines of Tome4
quite an undertaking you got there
that looks really nice
I've spent a year building the architecture so whilst I lack skills I don't lack dedication.
Totally agree! That's the bar I am aiming for.
oh wait that is Taj
Yes!
Haha, defnitely not mine!
http://www.thorpy.org/ seems to be the last one active
does CeGUI have pythonic bindings?
try this out
CeGUI has been around for ages
Crazy Eddie's GUI
Crap, the py bindings are a bit outdated as well
CEGui is made for C++
Python is not their focus
and if a maintainer quits, not much you can do
All you can do is search around and try things out
make sure to check your source into git and branch
That's what I've been doing tbh, buddy. This was pretty much my last ditch effort to find a hidden gem. ๐
Thanks for your help, mate.
why does kivy force you to import things like this:
from kivy.uix.widget import Widget
instead of calling
import kivy class MyWindow(kivy.uix.widget.Widget)
@final flicker well it's because Label widget class is located in a separate module named label (label.py)
The directory is kivy/uix/label
Or maybe I got you wrong?
does it force you?
hm, yeah, the sub packages are not imported automatically
automatically importing them even if you don't need would make app startup slower because of loading unneeded things.
Hi, I'm trying to execute something when the Mouse Right Click is well clicked
def eventFilter(self, QObject, event):
if event.type() == QEvent.MouseButtonPress:
if event.button() == Qt.RightButton:
print("Finally!")
Why is this not working?
@alpine blaze im working on my rendering engine and id love to be able to directly be able to interact with my Widget subclass
class MyApp(App):
def __init__(self):
super().__init__()
def build(self):
return MyWidget()
thats how im doing it right now
but id love to be able to just call MyWidget
this is the end goal:
class MyEngine(MyWidget):
def __init__(...):
super()...
def on_touch_down(self, touch): # this is overwriting the on_touch_down function in MyWidget
...
def on_update(self): # this is also overwriting a function that runs on a clock
...
if feel like doing this is kinda sketchy:
class MyApp(App):
def __init__(self):
super().__init__()
self.window = MyWidget(my_on_keyboard, other_event_function, ...)
self.root = self.window
kivy.clock.Clock.schedule_interval(self.window._update_data, 1 / 60)```
and then having all the actual event functions call the passed in args.
app.root always refers to the root widget of the app
so maybe you don't need all that contraption ๐
Hi, i was wondering if anyone could help with with Tkinter. I have spin boxes, and wanted to know if their was a way to check if they changed, so i can have some code run.
found it, just had to use command in the spinbox
I would like to make a GUI skinning tool (windows application) for a game's UI. It needs to have drag and edit functionalities like you would see in a design app or a user friendly 2d game engine (see image).
I'm searching for a program, api or library which could help me achieve this.
I have no ideal how to call this kind of functionality so I can't search for it online.
As far as I know (please tell me if I'm wrong) it's possible in pyqt but very difficult because you'd have to make it from the ground up.
Thanks in advance for any suggestions, links of open source projects with this functionality or terms!
is that godot in the background?
yup
nice
the basics of it's gui is a great example of what I'm trying to make.
a QGraphicsView would be a good choice for the canvas I think. It renders a QGraphicsScene, which manages a collection of renderable items such as widgets, shapes, pixmaps etc that can be placed at any position on the scene.
so you wouldnt have to reinvent any wheels as far as that's concerned
sounds good
is it only for displaying or would I be able to program user interaction in it?
you can intercept keyboard/mouse events and interact with the items on the scene however you want
check out this for how to implement drag n dropping https://doc.qt.io/qt-5/dnd.html
the examples are in c++ but should be fairly straightforward to translate to pyqt
and if you have any questions feel free to ask of course
another API you could use is Kivy, but im not as experienced with that so couldnt give you a worthwhile opinion on how well suited it is for this application. paging @alpine blaze
yeah, kivy seems appropriate to this, it's pretty much done to draw collections of arbitrary things, and to manage them by drag and drop.
you can check this very simple wysiwyg editor i hacked together sometime ago as an example https://gist.github.com/tshirtman/d1750e17c7cf268ff58536f3f7afbf2c
@molten swan
thanks! I'll try it with pyqt first because I already know it's basics, but it's a nice backup if I don't like the way it's done or get stuck in pyqt
ok, good luck either way ๐
@proper glade I'm a bit stuck. I need QGraphicsObjects for my QGraphicsScene because of their signals but QGraphicsScene only takes QGraphicsRectItems. I also can't instantiate any QGraphicsObjects because they are abstract. I could be wrong about what I just said but this is what I understood from it
I'm just testing things right now but in the actual project I will need to make my own classes and somehow add them to the QGraphicsScene
you can use addItem to add any QGraphicsItem to a scene
(and therefore QGraphicsObject since it inherits from QGraphicsItem)
ahh
i believe to instantiate a QGraphicsObject you can easily make your own concrete subtype, or inherit from one of the currently available graphics item types and also add your own signals to it
could I also inherit from QGraphicsItem itself?
I'm trying but getting some errors
class ShortNote(QGraphicsItem):
def __init__(self):
super(QGraphicsItem, self).__init__()
def dropEvent(event):
print(event)
so either:
class LineItemWithSignals(qt.QGraphicsLineItem, qt.QObject):
some_signal = pyqtSignal()
or something like ```python
class LineItemWithSignals(qt.QGraphicsLineItem):
class Signals(qt.QObject):
some_signal = pyqtSignal()
def __init__(*args, **kwargs):
super().__init__(*args, **kwargs)
self.signals = type(self).Signals()
yeah and you can inherit from QGraphicsObject to make it concrete
sorry, excuse the qt. prefix that's a force of habit
what errors are you getting?
one for super but that was fixed with *args, **kwargs
Can someone help me out over in the "help-0" chat later?
no prob
never done OOP in python nor with a 3th party framework yet so I'm still making some stupid mistakes
there's no need to go around to other channels and ask people to come to another one to help you
if someone sees your question and can help they will
Alright my bad.
Hi, i am using tkinter and have my gui code in interface(). I have spinboxes which call ReadData() when they change. I need to get the values of the spinboxes in this function. I tried making them global and using .get but i am just getting this <bound method Spinbox.get of <tkinter.Spinbox object .!spinbox>>.
Anyone know anything else i can try?
do you have parenthesis after get? you should be calling the function like so: get(), since just having get results in the function itself being assigned to the variable rather than the return value of that function
Would anyone be able to help me format this right? Storiestxtbox.insert('1.0',"\"", sbstitle[i],"\"", '\n', sbspubData[i]) I am trying to get this
Right now all it is inserting is
using print to test and it works, not sure why insert is getting different results
Storing it first is getting the closest result but is there anyway to stop it from showing {}
Still looking for some help ๐
'Storiestxtbox.insert(END, str(aqsdfa)[1:-1],"\n")' I've changed it to a str which work but the \n dose not seem to be working
fixed it with Storiestxtbox.insert(END, str(aqsdfa)[1:-1] + "\n\n")
@proper glade My items somehow move the view in the scene or something when I drag them on startup. But after doing it for a while it stops
@molten swan https://stackoverflow.com/a/47342558/10444096 this looks like it might solve your problem
note that setSceneRect is being called on the scene itself, with the rect of the view passed as argument
though it feels a bit backwards to me, like something that should be a function of the view rather than the scene
there we go, qgraphicsview has its own setSceneRect
noice
@proper glade I'm sorry to bother you again. Just tell me if you are not interested in helping me every now and then throughout my project. That being said, I'm trying to make a list of all my custom GraphicsItem types which I could then drag into the GraphicsScene
it's all good
but QListWidgets only accept QListWidgetItems and they don't seem to to be able to hold classes as data
thanks a lot
I tried giving my GraphicsItem classes QListWidgetItems
but when I .setText() it gives errors
and without it won't display in the list (don't know if it's not added or just invisible because it has no name)
giving a normal QListWidgetItems text and adding it works fine
just to be clear, the goal is to instantiate a new class I dragged in and add it to the scene
it's been a while since ive worked with a situation like this but iirc there are a couple drag/drop events you gotta override and also probably call something on the view to enable drops in the first place. gimme a couple minutes to play around with it and ill get back to you. as for QListWidgetItems holding classes as data, you can create your own subtypes that can hold a reference to anything like any other python object.
class MyQListWidgetItem(QListWidgetItem):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.customClass = object()
def setCustomClass(self, customClass):
self.customClass = customClass
something like this?
exactly
though self.customClass would just be object rather than object()
you want a reference to the class itself, rather than an instance of it
@proper glade, it looks like you tried to attach a file type we don't allow. Feel free to ask in #community-meta if you think this is a mistake.
and theres another file called qt.py which is just
from PyQt5.Qt import *
from PyQt5.Qt import Qt as constants
which i use in all my pyqt projects
anyway, the gist of it is that you gotta override a couple of drag*Event methods on the GraphicsView to accept the event
and also the thing with subclassing QListWidgetItem to store a reference to the class like before
everything good?
@molten swan
yes great
the view is autogenerated with a ui so I need to do some tweaking to my code
but I understand what to do
thanks
np
ah there should be a mapToScene for the setPos
so this instead
item.setPos(
self.mapToScene(event.pos())
)
๐
FINALLY got it to work
scene.addWidget returns the item while scene.addItem does not
so adding the QPushButton worked but my custom classes didn't while my custom classes did work when just added them to the scene in the MainWindow init
what are you working on
a 'design' application
a application you can design stuff with
I just added drag and drop of object with the help of meta
nicccce
basically a game engine but without functionalities. just position and some other properties of objects in a canvas
like the u.i very simple
thanks
soo you can make project with this
I'm not done with it yet but it wonn't get much more complex
ya i under stand
exactly
and custom skins for it would be nice
like you can pick in the setting for white or black or you can import you own
scene.addWidget returns the item while scene.addItem does not
right, doesn't make much sense when you already have the item there to pass as argument ๐
scene.addWidget takes a widget and returns an item so it cuts out the work of converting the widget into a QGraphicsWidgetItem first
there's no such extra work to be done with addItem
ahh
sorry, QGraphicsProxyWidget not QGraphicsWidgetItem
was kind of confusing because while debugging everything seemed to work and didn't think of something like that
but makes sense
https://doc.qt.io/qt-5/qgraphicsscene.html#public-functions check out all the return types of the add* methods here
everything's gotta be in QGraphicsItem form first to be added to the scene so they gotta be converted first
the add* methods just make that more convenient for you
does that mean that the items inside the scene lose all their custom code?
i think custom widget behaviour is carried over
as for custom code for things like lines and polygons, i doubt it
theyre meant to be used more as values than anything else
if you have your own custom subtype of QGraphicsItem and define custom behaviour for it then thatll be carried over to
but mine are kept since they already inherit from QGraphicsItem right?
yes, youre adding those items directly to the scene
rather than converting some other object into a qgraphicsitem first
Any PyGTK Veterans here? I'm having some trouble with TextView resizing with large amounts (correction: no, 5 paragraphs is NOT large) of text. It's fine reizing larger, but resizing smaller is excruciatingly slow UI wise.
Example with TextView with SpellCheck enabled
With less text it's not so bad.
has problems with both Spellcheck enabled and not enabled
TKInter seems to have no trouble with grid resizings :/
Tkinter isn't slow at all - it's uglier, but it seems to work
thats really weird
looks like a bug
tkinter struggles a lot with resizing when the grid has tonnes of stuff in it.
https://discordapp.com/channels/267624335836053506/338993628049571840/496484034516615171
Agreed. Itโs on a relatively fast machine using the proprietary Nvidia driver, but I had the same problem in a vm on a Mac host at work too.
I donโt see the grid getting incredibly huge, so I might continue down the tkinter path if I can get good inline spell checking working.
Still exploring ๐
I wonder if you could reproduce it if you ditched the wrapper and used gtk in c
Though I don't expect people in this server to all know C
I should try, but I was trying to keep it simple. Might try QT5 too
So i am working on text summarizer by python using nltk .
i have finished the code part and my program summarizes text fields passed .
I want to make this as a web app
Can anyone help me with the web/UI part ?
i am beginner in python
Am i going mental or has PyQt5 changed tbe way colSpan and rowSpan work? I cant get it to work in the newest version
@alpine blaze can i somehow tell a kivy texture to clear itself? or do i just have to set it to 0 ever time?
i don't think we have a specific api for that, setting it to 0 should be fine
ok thx
i dont really get this:
When using a bytes representation of the data, for every change you have to regenerate the bytes instance, from perhaps a list, which is very inefficient. When using a buffer object, you can simply edit parts of the original data. Similarly, unless starting with a bytes object, converting to bytes requires a full copy, however, when using a buffer instance, no memory is copied, except to upload it to the GPU.```
right now i have a 3d array (size[0], size[1], 3) and i just flatten it to blit it:
self.texture.blit_buffer(data.flatten(), colorfmt='rgb', bufferfmt='ubyte')
flatten certainly produce a copy that slow down things, and the explanation is that if you use a buffer object, it can update it in place, instead of creating a modified copy
is it the scrollbar?
Hey I just posted a project over in the projects channel. If anyone who is good with UI design is willing to help, I need an extra hand
is there a guide to writing events for qtwidgets?
I want to be able to essentially select a Qgraphicsview. Is there a easy way to set up an onclick even for Qgraphicsviews?
class ClickableGraphicsView(QtWidgets.QGraphicsView):
def __init__(self):
super().__init__()
def mousePressEvent(self, event):
print("Event works")
super().mousePressEvent(event)```
This is why I've tried, it doesn't seem to do anything though
seems to work perfectly here
are you clicking on an item?
could be receiving and consuming the event first instead of the view
im not entirely sure what the event processing order would be here
I've figured out the problem
thanks for the help meta, I wouldn't have figured it out without it ๐
what was it?
Anyone able to help with this? http://paste.ubuntu.com/p/d5XR8mK9Ys/
Everything is in the wrong row, and the buttons, which i want to be in two collumns at once, are only in one collumn
Nvm, i got it, but everything is still really spaced out like this. Is it just cause thats how big my phone is?
Hey guys, is anyone familiar with django-scheduler or something similar? I need to make an sscheduling calendar web app in Django, but im stuck. I searched every whole, and it seems that they are lack of documantation for that. JS has "fullcalendar", and im wondering is there something similar for django? (That actually works)
the mouseReleaseEvent() in my QGraphicsScene causes weird behavior while moving my QGraphicsItem
with the mouseReleaseEvent()
without the mouseReleaseEvent()
I don't know if you can see it but it stutters and teleports the item
my code:
import sys
from PyQt5.QtGui import QBrush, QColor
from PyQt5.QtCore import QRectF, Qt
from PyQt5.QtWidgets import QApplication, QMainWindow, QGraphicsScene, QGraphicsView, QGraphicsRectItem, QGraphicsItem
class MainWindow(QMainWindow):
def __init__(self, *args, **kwargs):
super(MainWindow, self).__init__(*args, **kwargs)
self.setGeometry(500, 200, 500, 500)
item_brush = QBrush(QColor(255, 255, 255))
item_brush.setStyle(Qt.SolidPattern)
item = QGraphicsRectItem(QRectF(50, 50, 100, 50))
item.setBrush(item_brush)
item.setFlag(QGraphicsItem.ItemIsMovable)
item.setFlag(QGraphicsItem.ItemIsSelectable)
scene = MyScene()
scene.addItem(item)
view_brush = QBrush(QColor(150, 150, 150))
view_brush.setStyle(Qt.SolidPattern)
view = QGraphicsView(scene)
view.setSceneRect(QRectF(view.rect()))
view.setBackgroundBrush(view_brush)
self.setCentralWidget(view)
class MyScene(QGraphicsScene):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
#def mouseReleaseEvent(self, event: 'QGraphicsSceneMouseEvent') -> None:
#pass
if __name__ == "__main__":
app = QApplication(sys.argv)
window = MainWindow()
window.show()
sys.exit(app.exec_())
make sure you call super().mouseReleaseEvent(event) when overriding
and also event.ignore() just to make sure it's not consumed
oh hmm, not sure about ignore() actually
but anyway my best guess would be that you need to call the super method to let all the normal mouse processing stuff happen
@elder valve according to the docs the 3rd and 4th args to addWidget in QGridLayout are span length not coords
https://doc.qt.io/qt-5/qgridlayout.html#addWidget-2
additionally you might need to do something with the alignments
@molten swan no worries
@elder valve also, i think the spacedoutness is just a byproduct of how QLineEdit is rendered
it's always meant to be a single line, so youll get the empty space around it
Ah okay, thanks @proper glade
for extra lines you might wanna check out https://doc.qt.io/qt-5/qplaintextedit.html
Yeah, i was gunna use QTextEdit, im tryna convert a JS+HTML quiz to python, was gun.a use QTextEdit as equivent of HTML textareas
Cause i wanna do formatting and stuff on the text.
which is better for ui? tkinter or QT ?
tkinter is to qt what a tricycle is to a spaceship
but in seriousness, it depends on what kind of ui you're making
you can use both to great effect
but qt is a lot more advanced and performant
the disadvantage is that you need to get familiar with the framework and it's larger
but if those don't matter to you, it can be a lot better
ok thanks guys
If using tkinter. How do I connect items in a nav menu to change to a different window
So people, what is your fav UI framework? Any opinions between PyQt and PySide2?
PySide2 has substantially better docs it seems and is supported (more?) directly by Qt. But the docs don't matter too much since both libraries are pretty faithful to the original Qt library and thus not only do PySide2 docs generally apply to PyQt5, so do the C++ docs. PySide2 also uses a less-strict license compare to PyQt5.
However, PyQT5 does have support for some additional things from Qt that PySide2 currently does not https://wiki.qt.io/Qt_for_Python_Missing_Bindings.
I use PySide2 but at the end of the day there hasn't been a huge difference for me.
I use Wx with WxFormBuilder. Never needed anything better. Works great for what I do.
Thanks both of you.
I was using PyQt for a while but wanted to use a UI framework that would allow me to create software that was closed source if i ever got the opportunity to sell some of my apps. Even if I were to sell apps, I know I could never ROI the license cost.
I tried some other UIs like Remi, Kivy, tkinter (again) as well as some of the other tkinter like bindings like PySimpleGUI and others. Some of those bindings are very easy to use and allow you to reduce the amount of code you have to write, but I have been finding the limits of those pretty quickly with a simple app.
I liked PyQt. I might have to give PySide2 a shot. Looking through the list of missing bindings in PySide2, I am not too worried. The apps I have planned currently would not need those
one thing i do not like is that VSCode tends to not like PySide2. Keeps saying that it cannot find the widgets, but the app still runs. I am still trying to whitelist QT5 in VSCode
But don't take my word for it
yea. those licenses confuse me
I dont "plan" on writing closed source, but i really want to keep that option open to me
I think the other really mature one would be PyGTK, at least that is my assumption since it's based on GTK, which is mature
yea
Should have features comparable to Qt
thanks. i will look into that as well
I thought kivy was also pretty up there
I wouldn't know I've not used it
an app i wrote in PyQt, i rewrote in kivy
the UI looked a LOT better. More like a phone app than a desktop app. But, at the time, the functionality wasn't all there. I don't know about it now. I have not been following it
hmmmm. I will have to look into PyGTK a bit more. It seems about the same in the coding sense and there is even a builder (Glade) that I could use for some simple apps most likely
thanks again. you gave me a lot to think about
bed time for me
shoot. PyGTK is out. The target I am writing apps for are windows users. Dang it, that looked good too
I'm having some trouble renaming QListWidgetItems with double click in PyQt
I'd like it to work basically like this
I've found some ways to do it in Qt on the internet but they somehow don't work (I'm probably doing something wrong)
what have you tried so far
what is kivy not mature enough for yet?
i mean, there are always things we can improve, but you can still do a lot of apps
i've done a lot of them, at least, and i'm far from alone
@alpine blaze i believe a lot of people (including myself) just dont like the structure of Kivy.
๐ฆ
The default look of kivy, however is something i like a hell of a lot
I just prefer to force PyQt5 to look pretty cause i like having access to the entirity of Qt5
weird, i though our default look was actually quite a disadvantage, people tend to judge that and think all apps will look like that, and that it's ugly
i guess the truth of the second assertion is debatable, but the first one is essentially wrong, as you can change everything and draw anything
but do you don't like in the structure? how widgets are built? the package tree? the dispatch system? the graphical instructions?
The package tree mostly, though i did find a nice little solution to that
Interesting, how would you see it instead?
Hey
I am using PySimpleGUI, I want to use a similar function like FileBrowse(), but for the menu option.
menu_def = [
[ '&File', ['Import::import_key', '---', 'Save::save_key'], sg.FileBrowse() ],
[ 'Help', ['About::about_key'] ]
]
How do I have the same functionality for an import that brings up file explorer so I can import a file with N file type?
@alpine blaze would be good to have a gui package, where i can import all of the gui elements like is possible with PyQt5.
@versed trout what do you mean Sasi? Like the label 341?? If so just do label = QLabel(text="341")
I think you actually helped me with the programatic import in the kivy server tshirtman, it was something along the lines of this ```python
imports = {
'uix' : ['Label', 'Button'],
}
for k, v in imports.items():
for I in v:
i = I.lower()
globals().update({I:getattr(import_module(f'kivy.{k}.{i}'), I)})
I did refine it later on i think, but i dont have that snippet handy right now
hm, so like uix, but with all widgets from the submodules directly imported into it?
Yeah, basically.
@elder valve I figured it out the problem was I was calling the error so it did not worked
*work
@versed trout okay, that doesnt sound like a thing that is possible but I'll take your word for it... feel free to explain yourself though
@elder valve i think we would need a way to do that that wouldn't impact the performances, because i think right now it would slow down app startup and certainly increase memory consumption overall
Yeah, the way that it's done is understandable, its just not fun to work with ๐ ๐
there is an easy alternative though
from kivy.factory import Factory as F
F.Button()
F.Label()
โฆ etc
That is something i had no idea existed. Wow, ive legitimately never seen that
what would one even search to find that given they don't know of its existence
(it works because all widgets in uix are registered in the factory in factory_registers.py, and you can have your own such module in your app to allow the same access to your widget without needing to preload them)
Thats p cool though, thanks!
Factory is used by kvlang to find the classes to use when you instanciate widgets in the string
Ah, that makes sense
yeah, it's the kind of things you kind of stumble upon :/
i should probably use it more in my examples to make people more aware of it
Yeah, lmao.
It would be good
Im probably going to use kivy more now that i know that.
but then i would need to explain why that works for kivy widgets, and not automatically for the widget classes defined by users, unless they have been imported before, or they use a similar factory_registers thing
hm, i'll try though ๐
Perhaps Factory could be renamed to builtins? Idk how many files you'd have to refactor, but it would make it a lot more self explanatory @alpine blaze
I also don't know whether that would mask its other functions, but one would assume if someone knows the other uses of Factory, a name change wouldn't confuse them too much. I doubt many people will use it at the moment. Of course you could just make a package whose sole purpose is an alias for Factory, and leave Factory in tact
i do think Factory is a proper name, and builtins would be a misrepresentation, i guess the solution is just more/better documentation
Yeah, unfortunate solution, but a solution nonetheless
@molten swan did you figure out your double clicking issue
Not yet. I put it to the side and did some things I do know how to do
But the internet says I only need to give the items an 'editable' flag (doesn't work tho)
Also, I gave my QGraphicsItems a dragenter, dragmove and drop event and setAcceptDrops(True) but they don't recieve it when they're in the scene
could it be that either the view or the scene receives it instead?
@proper glade
Hello is there any way in PyQt5 to make the same window with different functions automaticly and don't copy paste the same code of the window all the time ? If yes then how can I ?
create a base class?
@molten swan not sure regarding event processing order but should be trivial to figure out with some debug output. in case either the scene or the view is consuming the event, you can use their itemAt methods to find whatever widget is under the mouse. additionally dont forget to event.accept() for the drag events.
as for making list widget items editable:
self.setFlags(
self.flags() | qt.constants.ItemIsEditable,
)
on the item seems to be enough to make it editable
after i do this i can double click and edit the text inside with no extra effort
If I wanted to give my py program a UI what would I be looking at?
@undone cave if you want a cross-platform desktop UI I recommend PySide2, which is the official Python wrapper for the C++ library Qt
you don't
If you want a cross platform desktop and mobile UI, there is kivy, which is a python-first multitouch UI library.
Doesn't qt support multitouch? (Not saying it'd be a better choice for mobile)
can i put a scrollbar in a Tk() object
i mean
from tkinter import *
root = Tk()
root.mainloop()
```can i create a scrollbar for root?
Anyone?
You can for a Canvas, I don't believe you can for the root window
Hello guys
Guys I need a tkinterical help
Sorry for being late
does anyone know what is Entry?
It's a widget that allows the user to type into it, you are then able to later retrieve whatever they typed
GOod
Good
Ik it
but now that you'e familiar with it
you may be able to answer my real question
how to understand what is written in the entry part?
How to get what they typed?
yes
text = my_entry.get()
my_entry is your Entry widget, you need to call the get method on it which returns a string of what it contains
You could say that
๐
So can youy teach me?
iK SOMETHING ABOUT IT
sorry for caps
Ik some normal regular things
lemme send you my best tkinterical work
and then you decide if you wanna accept teaching me or not
So tkinter and QT4 or whatever. The only UI I've seen for these are like grayscale win98 windows. Can they make a cool UI like discord or any other program that's not grayscale and has icons and such?
Why after clicking a button it isn't showing me the text "Sucesfully Logged ?"
What is the if line supposed to be doing/checking?
Its about to check if there is password or username and email in file
!or-gotcha
When checking if something is equal to one thing or another, you might think that this is possible:
if favorite_fruit == 'grapefruit' or 'lemon':
print("That's a weird favorite fruit to have.")
After all, that's how you would normally phrase it in plain English. In Python, however, you have to have complete instructions on both sides of the logical operator.
So, if you want to check if something is equal to one thing or another, there are two common ways:
# Like this...
if favorite_fruit == 'grapefruit' or favorite_fruit == 'lemon':
print("That's a weird favorite fruit to have.")
# ...or like this.
if favorite_fruit in ('grapefruit', 'lemon'):
print("That's a weird favorite fruit to have.")
I think applies, and not sure you can just in a file object
Well I've changed but still it is not showing the password username or email in the file
still using f? reopening a file before closing it could be an issue there too
I belive you should do not in f.readlines() instead of not in f
if username1 and pass1 and email1 != username1 and pass1 and email1 in f:
in f.readlines()
like so you gonna get a list of all rows in your file
in an str form
['row1', 'row2', ...]
Well it looks now like this still doesn't works
well try to print f.readlines() cause I think it comes from the fact that there not 1 info by lines in your file
is data.txt empty ?
Yes
so that's why
email1 can't be in the file if the file is empty
as you said before you want to check if there is password or username and email in file and if they arent you want to write the email in the file ?
Yes this is what the function needs to do
Well I think I will rewrite the code
Now I've rewrited that function and now it is writing memory id into the txt file so now it is working
Is it possible to create modern GUIs like discord or any other desktop application in python?
kivy you can theme essentially however you like, & theres kivyMD for prewritten MaterialDesign widgets. Theres also various Qt wrappers
Hi guys!
I'm having some problems with tkinter
I'm new
from tkinter import *
from tkinter import scrolledtext
from tkinter import messagebox
from tkinter.ttk import Progressbar
from tkinter import filedialog
from tkinter import Menu
window = Tk()
window.title("My first TK!")
window.geometry("500x500")
text = Label(window, text="Hello there!", font=("Nunito", 30))
text.pack()
window.mainloop()
Why is the text cut off?
Does anyone know how to move elements to specific positions using pysimplegui? I can't seem to get my elements positioned properly
@craggy talon does this happen with the default font?
no
I haven't work with tkinter. but I had a similar problem with some fonts in kivy and pygame. I did not find a simple solution since I had a little time, so I just used different fonts.
I can't really help if I can't see your code
@scenic frost the code is above I guess
Well unless I'm mistaken I don't think that's the full code
im new to python gui and i am wondering if there are any better alternatives to tkinter?
Can anyone point me in the right direction for making a desktop app with Flask? @here
@digital rose certainly, but which one certainly depends on what your priorities are, i'm personally a fan (and contributor) of kivy, but a lot of people advocate pyqt/pyside for desktop apps, both have pros and cons.
yeah i am mostly interested in desktop apps
@lofty elbow flask is a backend, you need a way to display things, usually to build desktop apps with a web framework, you use electron or some other web view and front end technologies, html/css/js with react or vue or whatever to help build a modern front end.
Hi I'm making a TUI application.
(new to python so keep it simple please)
Pretty simple just imagine the main part of the window being output, ie print()
As well as a small box right at the bottom where you can input text. I have looked into curses for this and I roughly know how to do it. An issue I ran into is with the text box you can only type, backspace and return. No left/right or whatever.
I'm open to and libraries anyone suggests. Just want to get this done
@lofty elbow It is not impossible, but I wouldn't do it: https://www.techiediaries.com/flask-electron-tutorial/
Electron is what runs discord on desktop
@brisk thicket PyQT and your woes are gone. pyWxWidgets if you need commercial usage without paying
Kivy if you want more eye candy
thx
i though the question was TUI, not GUI
there are usually two kinds of TUI, the graphical-like ones, with boxes and things, like curses allows, and the more shell/terminal oriented ones, where you type commands with sometime very neat autocompletion and feedback.
Havenโt looked into the 2 thing suggested. Basically a curses wrapper would suit I think
Curses has very poor support for text input without a lot of work I donโt know how to do
Try out whiptail, I cant remember whether it was Unix only, but I should be able to give you some python bindings
@brisk thicket
Guys pls ping me when you wanted to answer
Do we have drag buttons in tkinter?
I mean like the circles we drag for example in color chooser and then colors change
I'm trying to use Kivy for the first time and just trying to get a scrollable list of buttons ```py
class MyApp(App):
def build(self):
layout = BoxLayout(orientation='vertical', size_hint_y=None)
for i in range(50):
layout.add_widget(Button(text=f'Button {i}', size_hint_y=0.1))
root = ScrollView(size=(Window.width, Window.height))
root.add_widget(layout)
return root```
This is what I have right now but it's very broken and I don't know what direction I should go
oh hmm, if I do layout.height = 12345 it kind kinda works
not what I want but closer to it
Update: I just used pyside2 and got it working 
@spare verge
from kivy.app import App
from kivy.lang import Builder
from kivy.uix.button import Button
from kivy.uix.boxlayout import BoxLayout
from kivy.core.window import Window
from kivy.uix.scrollview import ScrollView
class MyApp(App):
def build(self):
layout = BoxLayout(orientation='vertical', size_hint_y=None)
layout.bind(minimum_height=layout.setter('height')) #<-- add this
for i in range(50):
#layout.add_widget(Button(text=f'Button {i}', size_hint_y=0.1))
layout.add_widget(Button(text=f'Button {i}', size_hint_y=None))
root = ScrollView(size=(Window.width, Window.height))
root.add_widget(layout)
return root
MyApp().run()
I see
I used to do this using kv and GridLayout, something like this
from kivy.app import App
from kivy.lang import Builder
from kivy.uix.gridlayout import GridLayout
from kivy.uix.button import Button
KV = """
ScrollView:
size: self.size
MyGridLayout
cols: 1
size_hint_y: None
row_default_height: '50sp'
height: self.minimum_height
"""
class MyGridLayout(GridLayout):
def __init__(self, **kw):
super().__init__(**kw)
for i in range(50):
self.add_widget(Button(text= str(i)))
class MyApp(App):
def build(self):
return Builder.load_string(KV)
MyApp().run()
also RecycleView is good if I have many items
https://kivy.org/doc/stable/api-kivy.uix.recycleview.html
Yea, it's not quite intuitive and a little cumbersome, but I suppose it's necessary to keep ScrollView "universal"
btw I think itโs easy (at least definitely possible) to implement a widget that behaves like a simple BoxLayout but has ScrollView behavior
How do i make buttons black with PyQt5?
ty <3
no worries
i cant seem to get it right, nothings changing color;
self.setAutoFillBackground(True)
p2 = self.palette()
p2.setColor(self.backgroundRole(), Qt.red)
self.setPalette(p2)
im not sure how youd do it with palette objects but you can use a stylesheet like so:
some_button = QPushButton()
some_button.setStyleSheet('background-color: black; color: white;')
so thats html?
it's qss, basically css with some bells and whistles
cool cool
Guys pls ping me when you wanted to answer
Do we have drag buttons in tkinter?
I mean like the circles we drag for example in color chooser and then colors change
I'm trying to find some reference for "best practices" regarding building PyQt application, specifically to things like logging, good strategies for avoiding breaking C++ Object Already Deleted RuntimeErrors and so on
does anyone have experience in Kivy?
@green badger Just ask the question, someone is probably able to help
I do
nvm i figured it out
Cool now the rest of us don't get to learn ๐
Hi! Anyone know why the dropdown is automatically open, displaying all buttons?
<StationDropdown>:
id: stations
Button:
id: DropdownMainBtn
text: 'Stations'
size_hint_y: None
height: 44
# on_release:
Button:
text: 'Raadio 2'
size_hint_y: None
height: 44
# on_release:
Button:
text: 'SRF 4'
size_hint_y: None
height: 44
# on_release:
Kivy*
whats in the py
maybe you want a Spinner, not a DropDown
class StationDropdown(DropDown):
pass
Thats in the py.
Will check out Spinner, thanks
So the dropdown is meant to be an all-time-active widget?
it's meant to be dynamically added/removed from the widget tree, using its methods
this is what Spinner does
i know it's a bit confusing, but DropDown is a low level widget in kivy, kind of an implementation detail of Spinner, which is what people usually want
Hey im new to python and my img is not appearing using tkinter i have pillow installed and everything but the photo is just not displaying
def mainImg(self):
img = ImageTk.PhotoImage(Image.open("compickerlogo.jpg"))
label = Label(root, anchor=LEFT, image=img)
label.pack()
@agile barn I don't think you've placed the img
https://kivy.org/doc/stable/api-kivy.core.camera.html?highlight=camera#kivy.core.camera how would I use this in code?
https://kivy.org/doc/stable/examples/gen__camera__main__py.html the example I wanted
on windows, do you know how to launch vscode in debug or verbose mode ?
I had to install in user space, and crash at start (no admin rights).
i've only seen .net Framework requirements (4.5+ and i have 4.8)
@karmic shoal wdym what am I suppose to do
What GUI does you guys use and what do you recommend
Hey, how can i make the left Vertical layout be a fixed size? ๐ค i wanna resize it so its smaller
@!Pancake#0290 with the designer idk
I can tell you how to do it in the code tho
(I deeply hate the designer)
@stoic lynx I use Qt (QtWidgets to be accurate) because that's the one I know how to use ๐
@stoic lynx i use and love kivy (and i'm/have been quite involved in the dev) it's easy to get started with and has a few nice things, like being a python first lib (not a wrapper of a C++ one) which makes it more natural to use in python, it's multiplatform (including android and ios), and it gives the same result on all of them, (though some people would prefer a native-like look on all plateform, i'm not one of them).
With PyQt5 i made a calculator, it works.. i just want to be able to type the numbers with my keyboard instead of using the calculator on the screen, so much faster.
not sure how i would do that tho.
You can press enter and it will calculate the equation but you cant press numbers. ๐ค
(Please do ping me if you know how to help me with this ^^)
@Taste My Frost#5027 how did you learn pyqt5
Tutorials and such @stoic lynx
how would i update an image thats in a .kv file every second?
The kivy Clock object has a schedule_interval method you could use to call an updating function every second. Would that help? @green badger
@near lagoon Thanks! can you send me a code simple code example?
Sure, I only just got home though. Lemme see what I can do
@green badger Here's a button that updates its text with a random number every second:
from kivy.app import App
from kivy.uix.button import Button
from kivy.clock import Clock
from random import randint
class RandomButton(Button):
def __init__(self):
super().__init__()
Clock.schedule_interval(self.update_label, 1)
def update_label(self, dt):
self.text = str(randint(0, 10_000))
class Test(App):
def build(self):
return RandomButton()
Test().run()```
@green badger yeah, clock can help, but it really depends on what you want to do and how that widget relates to the rest of the app
so if you can give some more context, we might be able to provide a more precise answer
@digital rose what are you using to make the GUI
@digital rose next time you should say that. you need to be specific as possible eg
"How do i place gifs here in TkIner"
ah sorry
@digital rose np
are you familiar with tkiner?
@digital rose I used it once two years ago then frogot about it
Besides arcade & pygame, does anyone know of any other relatively-easy-to-use graphics-focused (not tkinter, pyside2, pyqt5...etc) gui libraries?
Are there any good beginner projects to get started with interfaces? I think I have a pretty decent beginner foundation for python, and am interested in GUI's as I feel like that opens up ALOT possibilities.
@amber burrow did you look at kivy?
@gentle sapphire the classical starting project is a notes/todolist manager, but you can get crazy and build other things.
@alpine blaze I actually made a decent to do list earlier today, and planned on implementing a GUI once I learned how to do it, but if thats a good place to start, then i guess ill start working on it
Thanks @alpine blaze , ill look into it
how would i put an image inside a floatlayout that i created inside my kv file
@green badger
FloatLayout
Image
source: '1.jpg'
@digital rose how would i create a image inside a float layout in a kv file inside a python file
@green badger
what do you mean?
don't you want to use kv file?
@digital rose lets say i create a floatlayout inside a kv file. I then want to create a image inside the aready existing kv file
@green badger
just add lines
Image
ย ย ย ย source: 'my_image.jpg'
inside your FloatLayout in kv
@digital rose I want to create the image inside my python file then put it inside the kv file
The simplest option for what you could do is use the "app" in the kv file as follows:
your kv file
FloatLayout
Image:
source: app.image_source
your main file (where your application runs from)
from kivy.app import App
class TestApp(App):
image_source = '1.jpg'
TestApp().run()
although itโs not always convenient
Hey guys, it's my first time working with GUI's and BS4, and I'm trying to display this HTML in a QTextBrowser (using PyQT5).
My current code to display the html is:
soup = BeautifulSoup(source, 'lxml')
table = soup.find('table')
self.textBrowser.append(str(table.prettify()))```
I'm trying to display the schedule of the soccer team Tottenham FC
What would be the best way to clean this up?:
I want to remove all timezones, and only only display the EST one, which I found here:
timeZone = soup.findAll("span", {"class":"shsTimezone shsESTZone"})
Any help?
@green badger the other way is to give an id to your layout and to refer to that id in the python code, if the id is in the root rule, you should be able to use app.root.ids.the_id and use add_widget on it, to create a new image widget with the source inside, if it's not in the root rule, then you do need to get a reference to the widget for that rule, usually giving it an id in the rule that contains it, up until you are back at the root rule, so you can use app.root.ids.some_id.ids.some_other_id.ids.the_id or something like this.
a recent convo reminded me about a problem I wanted to get to a few months ago, can I tell Qt to only keep a single instance of a window or delete it after it's closed?
say I create it like this
def end_route_pop(self):
w = popups.RouteFinishedPop(self.main_window)
w.show()
w.close_signal.connect(self.main_window.disconnect_signals)
w.new_route_signal.connect(self.new_route)
that runs fine but when the window is closed it stays in memory, while not much of a problem because tens of thousands of them would need to be opened to have a noticeable inpact, it's still I'd like to avoid
hallos, I'm looking for ideas for doing this better!
I'm just printing the status of some workers in a loop.
I'm interested in whether there's a better version of doing the screen update
โ ผ 2
โ 3
โ 4
โ ผ 5
โ ผ 6
โ ผ 7
โ 8
โ 9: Error: ...
โ ผ 10
from blessings import Terminal
...
term = Terminal()
while True:
....
for work, position in active_workers:
with term.location(x=0), term.hidden_cursor():
print(term.move_up * position, end="")
print(f"{work.status} {work.name}", end="")
....
sys.stdout.flush()
sleep(...)
you could use curses but that might be overkill
I'd probably clear the screen and include y=0 in term.location
instead of the move_up * position
that or get it all on one line (maybe skip printing the error information, i don't see how you're doing that) and just use '\r' instead of any library at all
oh, you can probably switch the term controls and the for loop
and just print them in order
hmm or something like py print('\n'*len(active_workers)+term.move_up*len(active_workers)) # clear space while True: with term.location(), term.hidden_cursor(): for work, position in active_workers: print(f"{work.status} {work.name}") # just print them on each line normally, the end of term.location() will move back to the top for the next time sleep...
@lyric cave
Well, the organization of the information is preferential. The error information presented magically through str, I just elided that.
I mostly care about alternative versions of terminal positioning.
What would curses look like for updating a line at worker_position? And would it work on Windows too?
i have no idea how or if blessings works on windows
like i said, curses might be overkill, it's a full screen management library rather than just moving the cursor
which lets you avoid garbage on the screen in edge cases like "what if an error message makes one of them take up more than one line"
just clearing the screen, and drawing the statuses from the top of the screen instead of near the bottom, might help with that too though
anyway
