Guys ,I want to structure my pyside2 project. This is the folder structure that I am thinking to go with. I am creating a gui using qtdesigner and then exporting it to python program so I wont be using .qml files for gui . There is utils folder for all utility funtions and also a resources folder where I will be placing all the icons and images to display on the gui. I will run my project using the main.py file. There will also be files that will be exported using the application. while the project will run normally using the terminal but if I am going to package my project using pyinstaller I am not sure it is going to function properly. If anyone of you have used pyinstaller before can suggest me how my folder structure should be and how I can package my project using pyinstaller using same folder structure
project /
utils /
init.py
file1.py
file2.py
views/
init.py
window1.py
window2.py
resources /
init.py
images/
icons/
exported_docs/
file1.csv
file2.csv
main.py
#user-interfaces
1 messages Β· Page 53 of 1
Am I using this correctly?
user = user_name_ent.get()
password = user_pass_ent.get()
ok_button = tk.Button(master=confirm_buttons_frm, text="OK",
command=lambda: create_user(user, password))
The create user function works independently just fine, but the parameters are not passed to the SQL DB.
Lambda has arguments too
lambda user, password: create_user(user, password) for example
That was just me trying something out. Even without the lambda the data is not passed
This is it now
ok_button = tk.Button(master=confirm_buttons_frm, text="OK",
command=create_user(user, password))
Might be something else in my code, I'm only a week in and no formal training
yeah, you have to get user and password from somewhere
Where do you define the 2 vars?
and also, this wont work as you have to pass a callback and dont call it
About 10 lines up
user_info_frm = tk.Frame(master=new_user_window)
user_name_ent = tk.Entry(master=user_info_frm, width=25)
user_name_lbl = tk.Label(master=user_info_frm, text="New user name")
user = user_name_ent.get()
user_pass_ent = tk.Entry(master=user_info_frm, width=25)
user_pass_lbl = tk.Label(master=user_info_frm, text="New user password")
password = user_pass_ent.get()
and whats the issue? the params do get passed, but it instantly gets executed
lambda should work tho
(the first implementation)
I have a function built that takes that info and puts it into an SQL data base. The other info that is defined inside the function is added but nothing but blanks in the user and pass fields
No, not anywhere in the code
So this issue is that the .get() functions aren't grabbing what's inputted into that entry box or that the information isn't get appropriately saved to the db?
correct
!paste could you paste your full code here?
Pasting large amounts of code
If your code is too long to fit in a codeblock in discord, you can paste your code here:
https://paste.pydis.com/
After pasting your code, save it by clicking the floppy disk icon in the top right, or by typing ctrl + S. After doing that, the URL should change. Copy the URL and post it here so others can see it.
I might have messed some stuff up trying to fix it
I can link the working code I had yesterday that the function is based on, it's saved on git hub.
In your create_user() function, you re-define user and password to "", overwriting whatever is passed in
Yeah, that was something I added trying to fix. I removed them and its the same issue
well, you definitely want to use the lambda in that command= call you had earlier
gotcha, let me try readding that without the arguments in the function
OH. I know what the issue is
π
You want your command code to be:
ok_button = tk.Button(master=confirm_buttons_frm, text="OK",
command=lambda: create_user(user_name_ent.get(), user_pass_ent.get()))
the GUI only launches once your code reaches root.mainloop(), anything before that is run before the user can even interact with it
So your code where you grab the user and password is done before the user has entered anything, hence why it's returning the blank strings
The code above will only pull the values from the entry boxes when the user presses the button
Awesome, I'll check that as soon as I get back. Thank you! I'm still very new to this. You rock
No worries~ happy to help
Hey! I'm trying to make a GUI in PyQt5 for editing a JSON list of hundreds of thousands of words. Since the list is so long, it's literally impossible to display it all in one label without it crashing, which is to be expected. So, I thought a good workaround would be to use tabs that dynamically load a long enough list of words where it is just short enough to not crash (however, at the moment I am just displaying 64 words per tab). I was originally going to use QTabWidget but I realized that it needed to have all the tabs in memory for it to work, which is even worse than just the list. However, I found that I can create just a QTabBar by itself to avoid this. But, for some reason, my QTabBar isn't emitting the currentChange() signal when I switch tabs. Any ideas what I am doing wrong? Or is there any better ways to do this? Sorry if my code is messy, I'm very new to Qt so only got the hang of it a few hours ago lol
Here's my full code at the moment: https://hastebin.com/orepuzodey.rb
@buoyant tendon Are you actually using a QLabel or something like QTextEdit/ QTextBrowser?
I don't know what QTextEdit or QTextBrowser are so a QLabel π
So I highly recommend using a QTextEdit. It'll be better suited for displaying a list of text items.
I feel like there will be no possible way to display 600,000 words at once without significant lag, though
mmmm, let me test something real fast
Is it better to store settings for an app in json?
Could you please explain how QTextEdit would do this? As far as I can tell, it just makes you able to have both rich text and standard text in one object, which is anything sounds like it would be worse for performance
Is it better to store settings for an app in json?
Some app like Visual Studio Code do it.
It's also worth noting I plan on making each of these words selectable so you can run functions on many words at once (deleting them from the list, duplicating them, making a filter with them...)
What's about QPlainTextEdit? https://doc.qt.io/qt-5/qtwidgets-mainwindows-application-example.html
Let me have a look
QTextEdit also OK. https://doc.qt.io/qt-5/qtwidgets-richtext-syntaxhighlighter-example.html
That's a lot of code and information @_@ I don't quite know what I'm supposed to be looking at
I mean, QTextEdit works for me. It takes a bit to do ctrl+c and ctrl+v and it takes a bit to spin it up, but I don't know how you'd get past that with over half a million words.
I just give you some examples of building a text editor in QT.
Well, surely the option would just to be to display only a small amount of words at any one time, which is what I was originally trying to do?
Well you said it was literally impossible to display it without crashing, which is not the case with QTextEdit.
But for the signal not emitting, can you post your code for how you're using the signal?
I don't see where you actually connect to the signal though. Are you familiar with how Qt's signal/slots work?
As far as I knew, I was just overriding a function on the parent class and when an event occurs, that function is called? It worked for resizeEvent so I thought it would be the same for the currentChange one
That's not really how Qt's signals/slots are intended to work
There is a currentChanged() signal for QTabBar
Uhm... let me write up a quick example for how it's typically supposed to be used
I think that'll be the clearest way
Alright, thank you π
give meeeeee 3 minutes
@buoyant tendon Check out this code for how to connect your own function to a pyqt signal. It's super basic but hopefully it's clear.
from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
from PyQt5.QtGui import *
import sys
class MainWindow(QMainWindow):
def __init__(self, *args, **kwargs):
super(MainWindow, self).__init__(*args, **kwargs)
self.mywidget = QTabBar()
layout = QVBoxLayout()
# Setting up a super basic QTabBar with 2 tabs
layout.addWidget(self.mywidget)
self.mywidget.insertTab(0, "Tab 1")
self.mywidget.insertTab(1, "Tab 2")
# Let's connect to the signal 'currentChanged' and attach it to our own function 'tab_changed'
self.mywidget.currentChanged.connect(self.tab_changed)
# Adding it to the layout
widget = QWidget()
widget.setLayout(layout)
self.setCentralWidget(widget)
def tab_changed(self, *args):
print("tab changed!")
print(args)
app = QApplication(sys.argv)
window = MainWindow()
window.show()
app.exec_()
mmmm probably should've paste bin'd that but oh well
Ah, so I don't even need a need class for it π
Thank you so much, let me try it π
It's still useful to subclass if your tabs will have unique functionality, but yeah. That's how you connect your own functions to the signals emitted by the default classes.
If you make your own subclasses you can also add your own signals which is useful
You'd typically only need to override the existing signals if you want to fundamentally change behavior that pyqt does.
It's not common that you'd need to do that
Makes sense
I really like the design behind pyqt's signals and slots~
It works π Thanks so much π
How do i close all my secondary window when i close my main window? I have three window classes; QMainWindow and two QWidget
@plush stream
you can connect the close function i am pretty sure to another function as well as the self.close() functtion
so inside that function you can make an instance of your other classes or windows
and close them all there as well
Okay thanks, but how do i connect the close button in the title bar? I know how to do it in tkinter but not in pyqt
wdym @plush stream
are you using the standard windows title bar
the method i said for will work well with a custom title bar and custom close button
Yes i did
i am not sure how to do it for the standard title bar
maybe look it up
but should be the same way i said except the button or connecting will be different
i suppose
Okay, thanks π
np
in tkinter, is it better to to:
a = Label(root, text="hi")
a.pack()
or:
a = Label(root, text="hi").pack()
?
first method is more readable i think especially if you add some parameters on pack() method
I'm stuck trying to plot realtime data, could someone give me a hand?
What framework are you using?
Umm, I'm working on Pycharm. I have tried to plot with pyplot and with pyqtgraph (that you mention a few days ago). Sorry if I don't answer properly, I'm a newbie π
This is a part of the script:
import pyRofex
import pandas as pd
AL30_T2 = "AL30 - 48hs"
AL30D_T2 = "AL30D - 48hs"
tickers = [(AL30_T2, None, None, None, None, None),
(AL30D_T2, None, None, None, None, None)]
Create empty DataFrame to store Data
prices = pd.DataFrame(tickers, columns=["Ticker", "Time", "Price"])
Initialize the API connection
pyRofex.initialize(config.user, config.password, config.account, pyRofex.Environment.REMARKET)
def market_data_handler(message):
prices.loc[prices['Ticker'] == message["instrumentId"]["symbol"], 'Time'] = message["marketData"]["LA"].get("time", None)
prices.loc[prices['Ticker'] == message["instrumentId"]["symbol"], 'Price'] = message["marketData"]["LA"].get("price", None)
pyRofex.init_websocket_connection(market_data_handler=market_data_handler)
pyRofex.market_data_subscription(
tickers=[AL30_T2,
AL30D_T2],
entries=[pyRofex.MarketDataEntry.LAST],
depth=1)
It's a websocket connection that received market data from two items. I need to graph the timestamp in the x-axis, and the price in the y-axis, like a time series; I've tried to update the plot but I couldn't. Sorry if my message it's too long or not proper
So which plot are you using for the script?
i trying with pyqtgraph, beating my head against a stone wall
So, overall your code should probably be structured something like:
function that receives/pulls data --calls--> function that processes data --calls--> update your pyqtgraph data + call .processEvents() to get the graph to update
Done! great help, greatly clarifying
pw = pg.plot()
while True:
pw.plot(date, price, clear=True)
pg.QtGui.QApplication.processEvents()
And works! just need to beautify the x-axis π
how to insert something into a text widget in tkinter?
just text.insert('text_to_insert')?
assuming text is the widget name
welp, didn't work
ok i figured it out π
thanks again for the help
Guuuys why isn't Kivy installing on Manjaro Python 3.8.5 , and it gives ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output....Any solutions? On windows this gave the same error, but when I tried Python 3.6 , it works
(The Kivy installation Python 3.6 works on windows , not sure about linux)
Oh nvm it worked with yay -S python-kivy
pip install --pre kivy[base]
If anyone has the time, I'd appreciate any feedback on this: https://paste.pythondiscord.com/ixerecaxec.rb
can i send emails through tkinter, not to spam or anything as i dont wanna break rule 5 but for something like app verification?
i am building a kivy app for android and the app needs internet, while packaging the app
Buildozer doesn't add the permissons i specify to the Manifest. So the app now can't access the internet ? anyone faced this ? how to fix this ?
hi
What permission(s) are set in your spec?
What permission(s) are set in your spec?
@tribal path INTERNET
isn't that how i do it ?
the permission i need is android.permission.INTERNET in the manifest.
Uncommenting the permissions line in the spec will provide that
Okay.. Thankyou.. i will try
You may hit certificate issue, for which you need to use certifi, see first if just that permissiin is all that was needed
Hi guys i have a question.
My class and I are building a room finder for our school building with voice command. As i am in the coding and UI/UX team we are currently looking for a GUI librarie which can both show text formatted well and display images easily. In the best case scenario wallpapers are also easy to programm.
If you guys have any suggestion on which libary to use i'm happy to hear them π
P.S. as obvious it should be MEGA complicated
tkinter?
You may hit certificate issue, for which you need to use certifi, see first if just that permissiin is all that was needed
@tribal path i faced it and fixed it by setting an environment variable..
Yea its a straight forward enough fix, especially with certifi
Yea its a straight forward enough fix, especially with certifi
@tribal path when i try to install it in my emulator i getINSTALL_FAILED_NO_MATCHING_ABIS
What arch is the emulator? x86_64 I assume, havent used emulators in a while so didnt know they were that restrictive. An actual emulator like bluestacks/nox would run them fine. So either that or create an arm/64 emulator I if I assumed correctly
I am using Anbox(linux)
https://github.com/anbox/anbox#install-and-run-android-applications
Yea its a x86_64 image, seemingly without an arm emulation layer. You can set the arch for buildozer to build for in the spec, x86_64 likely not used very much so potential for bugs
What OS are you on?
Then it's part of the standard library, you shouldn't need to install it
In your script you just need to something along the lines of import tkinter as tk
How do I do so that the text of the label changes every second?
I tried using time.sleep(1) but it doesn't work. I'm using PyQt5 and Qtdesigner it
in tkinter how do i insert to an entry what is said on a button
so lets say i have the number 5 on the button and a number 1 on a button, when i press one or the other (there are a total of 9 buttons) i want to print what is said on the button
i could show you what i mean through a code
so anyway here is the code
self.exit_button = Button(master, text = "Exit", pady = 20, padx = 20, command = master.quit)
self.exit_button.grid(row = 2, column = 0)
self.clear_button = Button(master, text = "CE", padx = 20, pady = 20, command = self.clear_entry)
self.clear_button.grid(row = 2, column = 1)
self.zero = Button(master, text = "0", command = self.insert_number)
self.zero.grid(row = 3, column = 0, ipadx = 25, ipady = 25)
self.one = Button(master, text = "1", command = self.insert_number)
self.one.grid(row = 3, column = 1, ipadx = 25, ipady = 25)
self.two = Button(master, text = "2", command = self.insert_number)
self.two.grid(row = 4, column = 0, ipadx = 25, ipady = 25)
self.three = Button(master, text = "3", command = self.insert_number)
self.three.grid(row = 4, column = 1, ipadx = 25, ipady = 25)
self.four = Button(master, text = "4", command = self.insert_number)
self.four.grid(row = 5, column = 0, ipadx = 25, ipady = 25)
self.five = Button(master, text = "5", command = self.insert_number)
self.five.grid(row = 5, column = 1, ipadx = 25, ipady = 25)
self.six = Button(master, text = "6", command = self.insert_number)
self.six.grid(row = 6, column = 0, ipadx = 25, ipady = 25)
self.seven = Button(master, text = "7", command = self.insert_number)
self.seven.grid(row = 6, column = 1, ipadx = 25, ipady = 25)
self.eight = Button(master, text = "8", command = self.insert_number)
self.eight.grid(row = 7, column = 0, ipadx = 25, ipady = 25)
self.nine = Button(master, text = "9", command = self.insert_number)
self.nine.grid(row = 7, column = 1, ipadx = 25, ipady = 25)
i have nine buttons here
each has a text on it
when that specific button is clicked i want to be able to print its text on the screen
hmmm let me try this
hmm
i was thinking of adding all of these variables to a tuple
or a list
but more a tuple because it is immutable
so anyway i was thinking of adding it to a tuple and making that tuple with all those variables an instance of the Button class
then i could just do this
@silver kelp You want to use QTimer, not time.sleep
but i dont know if i could do it
umm
anyway if somebody knows how to do it thanks for helping
this is what i have so far:
import tkinter as tk
from tkinter import *
def printSomethingelse():
for x in range(1):
label = Label(root, text= str(2))
label.pack()
def printSomething():
for x in range(1):
label = Label(root, text= str(1))
label.pack()
root = Tk()
button = Button(root, text="1", command=printSomething)
button.pack()
button = Button(root, text="2", command=printSomethingelse)
root.mainloop()
It shows a button saying 1 and when you click it,
it prints 1
Other than that,
I can't really help
sorry
yeah thats too long
i need it short
that would be many lines of code
if it was shorter i would do it that way but now in this case it would be too long.
even if you removed the spaces?
yes there r 9 numbers
i would need to write 9 different methods (because it is in a class)
its ok thanks for helping. your way is not bad, its just that now i have 9 numbers
if i would have 2, your way would work very well
but now i need a shorter way because i dont want to write extra lines of code
I'll keep looking
this could be a solution if you fit self.insert_number accordingly
self.btns = []
for i in range(11):
def _handler(n=i):
self.insert_number(n)
btn = tk.Button(master, text=str(i), command=_handler)
btn.grid(row=3+i//2, column=i%2, ipadx=25, ipady=25)
self.btns.append(btn)
using the _handler like that for default arguments is super icky but unfortunately the only way
yeah
i dont think so
for me it works
thanks @amber roost
@rose trench thats because you need to create a class
copy this code
and dont do it idle please dont
idle?
yeah u r using idle
idle is the python REPL
you use it do run test code and stuff
but you shouldnt use it for long code and stuff
you can use idle for simple statements
like if statement a loop, etc
i use idle to test some things out
my pc takes too long to load a ide if thats what your saying
its really good because you dont have to save the code on your pc
idle is not an IDE
it is an REPL
read evaluate print loop
it is usually used to REPL (read evaluate print loop). idle is really good to start learning python and to learn the basics of it
after IDEs come in handy once you start making projects like tkinter projects
but you can always use the editor within IDLE
yes
I open it with the cmd thing
ok good
oh wow
Idle is itself a tkinter app
thats good
how long have you been programming
like 11 months
thats good
i don't think it is that long
(Its of note as running in idle, you can get away with note stating a mainloop as idle is already running one)
i started python 3 years ago, i did 3 months of python then i stopped and then, i came back to it now so basically i have like 6-7 months of programming
it was very hard for me 3 years ago
so i stopped
but now i understand it better
lol i have stopped for 3 months and now i started again
nice thats how i am learning
i also bought a book from one of the people in the server
paul craven
his book is rlly good as well
and i bought a book by matt harisson
I can't get them unless there in whsmith : (
I'm currently reading this python book from Mike McGrath
Im on 2nd edition,
I skipped the first
I knew lots of book 1
How can i change the color of the QPushButton widget with the colour i choose in colorPicker dialog?
nice
Not tkinter i mean pyqt5 button
sorry i cannot help
hey guys, does anyone know how to pack widgets next to each other in tkinter? like side by side? I have an app that packs everything going down, like a list, but there is one widget that I want to be to the right of another
Pyqt5 or tkinter ?
@normal wing
tkinter
Use attributes side="left"on all widgets u want to stack side by side
Maye this can help
so like "button1.pack(side='left')"?
hi ! someone can help me plz ? i got an error there :
your variable is capitalized, like "Width", but when you set it, you used a lower case "Width=width"
so just change your variable "Width" to a lowercase w
on line 10
@wooden osprey
ohh thks
I'm compiling my application with PyInstaller, but it keeps crashing in certain situations. To debug this I pass the -c option to PyInstaller, but it doesn't lock the command line.
HI guys , totally new to UI dev in python. where is a good place I can learn about PyQT ? I am using this to create some VFX tools . if anyone know anything about that also would be helpful
I learnt the basics of PyQt5 from Tech with Tim's YouTube channel.
tech with tim is cool
Hello. So the scenario is that Iβm trying to link a python script as backend to a front end. How do I make a front end with very decent UI. Like what language and how do I link it with python
No tkinter please no
Something that looks more like in this century
Please
Pyqt/Pyside2
or you can use eel to develop front end with css/html/js and connect backend with python
recommend you search these up to get a good idea on what you want to use
No tkinter please no
Something that looks more like in this century
Most framework can be customized to whatever look you like. Just going with default is sorta like using HTML without CSS
The more you know about tkinter, the worse it becomes.
not really good if youβre planning to make anything advanced.
Well... can't say I have a lot of experience with it
so you might be correct
was just commenting on the fact that he thinks it looks outdated
if you punch it in the right ways, you can make tkinter look really decent
although it will involve ttk's create_image command and that always slows down redrawing upon window resize really heavily
it has very low resolution and quality
Popen(['ssh','-o' ,'StrictHostKeyChecking=no','-R','80:localhost:8080','ssh.localhost.run'],stdout=open('link.url','w'),stderr=DEVNULL)
This causes the stdout to hang , is there any way to perform this in the background , without halting the main program/stdout.
Why I am getting output like this? Any way to fix this?
https://hastebin.com/nilucoqahe.py
guys i need help w tkinter & time module
how do i get a countdown to display on my tkinter window using the time module
this is what ive done
from tkinter import *
import tkinter as tk
import time
window = tk.Tk()
window.geometry("200x200")
timer = 0
def timer_test():
global timer
while timer != 10:
timer += 1
time.sleep(1)
window.update()
return timer
lbl = Label(window, text=timer)
lbl.pack()
window.mainloop()
it only displays a 0 on my window thats all
please help
bc you don't call the function @digital rose
yea but theres more issues too
heres the solution
from tkinter import *
import tkinter as tk
import time
window = tk.Tk()
window.geometry("200x200")
timer = 10 + 2
lbl = Label(window, text=str(timer))
def timer_test():
global timer
while timer != 0:
timer -= 1
time.sleep(1)
lbl.configure(text=str(timer))
lbl.pack()
window.update()
timer_test()
lbl.pack()
window.mainloop()
@digital rose you're calling your timer_test() function before you GUI can even run. You want to call it through a button press probably
@static cove can you fix the code and send it to me here?
So, what do you want your code to do? You have a timer, but it's unclear how you want to start/stop the timer
i just want it to countdown
i have a project in mind
i just want to get this component clear
I'm trying to port a Tkinter-based folder picker to Gtk, and while this works it seems to hang. It looks like I'm supposed to use GObject.idle_add() to make it immediately show the dialog but I'm not sure where to add it ```python
import gi
gi.require_version("Gtk", "3.0")
from gi.repository import Gtk
def select_directory(title: str):
dialog = Gtk.FileChooserDialog(title=title,
parent=None,
action=Gtk.FileChooserAction.SELECT_FOLDER)
dialog.add_buttons(Gtk.STOCK_CANCEL,
Gtk.ResponseType.CANCEL,
"Select",
Gtk.ResponseType.OK)
response = dialog.run()
if response == Gtk.ResponseType.OK:
result = dialog.get_filename()
else:
result = ''
dialog.destroy()
return result
directory = select_directory('Select Ren'Py Projects Directory')
print(f'Directory selected: {directory}')
Anyone know how to improve this?
im trying to use pyqt5 to display a video, but whenever i tried to play it i always got an error saying DirectShowPlayerService::doRender: Unresolved error code 0x80040266 (IDispatch error #102). i searched this up and one of the solutions was to download the K-Lite codec pack, is this safe?
@digital rose well, it'll be easier if you create a class for your window, otherwise we can start the countdown with a button press
@static cove may i dm you?
@digital rose I'd prefer to help in this channel or in one of the help channels.
@digital rose try to avoid update method on your app Root because its already a big loop. You can use After() method or update_idletask instead.
@visual stag i found a good example in this doc : https://python-gtk-3-tutorial.readthedocs.io/en/latest/dialogs.html
@inner nest I actually borrowed snippets from that page to make the folder chooser. Even when I copied the whole example and ran it, it would hang for about 10s after clicking the button before opening the picker dialog
Hello. So the scenario is that Iβm trying to link a python script as backend to a front end. How do I make a front end with very decent UI. Like what language and how do I link it with python
@distant sand pyqt5
What do yall suggest Tkinter or Gi? or are they for diff applications.
Hi Guys I have a OOP question . its regarding the super() method.
I know the following usage of super()
def _init_(self, var_1, var_2, var_3 ):
super()._init_(var_1, var_2)
self.var_3 = var_3```
so in this case the super method says to get var 1 and 2 from the ParentClass and the var 3 from the this _init_ method right ? I just saw some code where it was like below.
```class MainWindow(QtWidgets.QMainWindow):
def _init_(self):
super(MainWindow, self)._init_()```
this time the variables are inside super(....) and not super()._init_(.....) like before. I am confused at what this is doing ? any help is appreciated
@teal hearth they're two different things
notice that in the first case stuff is passed to __init__
and in the second case stuff is passed to super()
and in the second case stuff is passed to
super()
@tawdry idol this is, loosely speaking, to helpsuper()find out which superclass you want the__init__from
in the first case you could well do super(MyClass, self).__init__(var_1, var_2) (incidentally, note that it's two underscores, so your code is wrong)
for the same effect.
and I believe that was necessary in Python 2, but no longer
look up help(super), that might help.
@tawdry idol thank you . yeah I mispelled the double underscore. sorry. so If super(MainWindow, self).__init__() means which super class I want __init__ from . why am I supposed to define it in the MainWindow class it self. I am already inside the MainWindow class and in the init function as well. why do I need to explicitly say that there ? to prevent it from accessing the Qt.Widgets.QMainwindow class's init function ?
Yea its unneeded in py3. Its py2 syntax, but will work in py3 as well. If you dont need to add code to the subclassed init, you dont need to define one at all
Hi, I have been advancing my Python knowledge with some textbooks and tutorials for a considerable time. I have been using VSCode and happy with it so far.
I am now setting my environment for web and data science projects.
To me it seems like the only thing I need as an extra is Jupyter, but should I really need to install Anaconda or an IDE such as Pycharm?
no you can use jupyter in vscode
@bronze basin which extension specifically?
@cedar crescent
no extension i dont think
its in-built with the pylance extension or with vscode itself
this should solve your queries
why is sqlite3 so slow?
sometimes it workes fine, but other times:
@timing
def update_setting(self, setting: str, value) -> None:
self.cursor.execute(
f'UPDATE settings SET {setting}=:value',
{'value': self.real_to_sql(setting, value)}
)
where @timing is (it prints the time the function took to run):
def timing(f):
def wrap(*args, **kwargs):
time1 = time.time()
ret = f(*args, **kwargs)
time2 = time.time()
print('{:s} function took {:.3f} seconds'.format(f.__name__, (time2-time1)))
return ret
return wrap
printed
update_setting function took 3.557 seconds
!!!
note that sometimes this function only takes like 0.005 seconds to run.
the table settings only contains one row, then why does it take so long??
I am using multithreading with qt
any ideas?
is there a clean solution for this error
File "<COMObject <unknown>>", line 2, in Item
pywintypes.com_error: (-2147417842, 'The application called an interface that was marshalled for a different thread.', None, None)
found something on stackexchange that explains whats going wrong but nothing on how to fix it
!paste
https://paste.pythondiscord.com/kehuruxuyu.rb The problem I would like to solve is that each of these update functions take like 2-4 seconds to run and that is way too slow especially when they are in series. it takes something like 10-20 seconds to run them. id prefer running them all in about 1 second but idk if i could ever acheive speeds that fast\
@bronze basin Exactly! Thank you!
Has anybody attempted to use PyForms? It looks like a really attractive option for GUI dev - especially for newbies who have trouble learning tkinter at the same time as the rest of python
I use pyqt5..and it's a great for making mordern ui too..i want to know is there any way to detect my mouse when it's over an targeted widget?
I mean i want to open a menu when the user just keep the cursor on that button..?
@kindred ferry
Usage: widget.underMouse()
(connect to a function like : self.function)
for examle
@bronze basin
Yeah i got it..
UnderMouse( ) function only return bool type so we have to make an loop and if statrments to get my work done
Anyone particularly knowledgeable in Blender Python scripting or might be able to point me to a specific discord more geared towards that area of application. I am currently working on an addon for Blender that utilizes python and stuck on pie menus, specifically operators and enum properties. What i'd like is a pie that has 8 options in the center with set of side buttons on a panel to control which set of 8 options is showing. I am not quite entirely certain how to phrase this into a question on stack overflow so must of my searches there have only taken me so far. Any help is greatly appreciated, if not just a point in the right direction towards who might know.
Have you tried the blender discord? https://discord.com/invite/blender
@lavish trail
Not yet.
I'd imagine its probably the best place for something specific like that. I haven't seen many mentions of Blender/Nuke or any other VFX related stuff on this server
Uhmm
@lavish trail I am doing blender Dev as well. you should checkout that earlier sent discord plus the blender developer chat
Hi everyone, does someone know how I can create these collapsable containers in Autodesk Maya? (I'm using PySide2)
How do i set the opacity of the whole ui in pyqt? (excluding the window)
If i use the self.setWindowOpacity() it will set the opacity of the whole thing including the title bar
Okay I've gotten a little further, is there a way to get all children of a PySide2.QtWidgets.QWidget object?
findChildren
Thanks, I found out I could do what I needed by using .layout() on the QWidget
@plush stream you need to create a custom frameless widget and it needs a widget to mock the functionality of a title bar. Then use the custom window to wrap your widget
if you do that you can apply the transparency to all but the title bar or just certain portions of the UI
I see, thanks
is it possible that i made a calculator.py where i made a simple calci which didnt had gui
so if i made another file.py where there is a gui interface
so am i able to write an open function to open my gui in my calci
Is there a python module or built-in function to automatically swap active window/program when a python script is launched? Let's say I want windows to bring photoshop to the foreground automatically when the script starts.
@sonic sonnet sure, you can make a call from like button gui to your calculator function
I am attempting to make my life easier by generating input fields with a for loop:
for y in self.data_needed:
self.row=tk.Frame(self.user_data_info_frm)
self.lab=tk.Label(self.row, width=15, text=y, anchor='w')
self.ent=tk.Entry(self.row)
self.input_data.append(self.ent.get())
self.row.pack(side=tk.TOP, fill=tk.X, padx=5,pady=5)
self.lab.pack(side=tk.LEFT)
self.ent.pack(side=tk.RIGHT, expand=tk.YES, fill=tk.X)```
However, I can't manage to pull the data from it, or if I do, it's only the last entry. Is what I am attempting possible?
I have pasted my whole code here and my previous attempt to pull the info from the fields. https://paste.pythondiscord.com/jeqafehubi.rb
Hey @runic patrol!
It looks like you tried to attach a Python file - please use a code-pasting service such as https://paste.pythondiscord.com
HELP CAN'T GET GUI TO WORK https://paste.pythondiscord.com/jomatupafu.rb
@digital rose what specifically do you need help with?
SO whenever i try to open import the second (temperature_window.py) in main.py
and run the main.py without even calling anything from second file just import
it opens the second window
and the first window never opens
@static cove
what does temperature_window.py look like?
take a look at second screenshot
That doesn't show me what the file itself looks like
i didn't get it, did you mean how the UI Looks like or How the code looks like?
the code
Is that what your temperature_window.py looks like?
that would be the problem then. You need to keep that if __name__ == "__main__":
if i keep it then the second UI aka Chart Ui will never show up
Well, you need to create an instance of the DynamicSpline class and then use it for it to show up
ok can you just simply tell me How to open a second window in PyQt , that would be easier for both of us
How much experience with pyqt do you have?
almost begginner
i've done few projects but this is going to be the most complex so far for me
Then check out this tutorial. It'll do a good job of walking you through how to open a second window. Then you can use that logic/concept to open the second window the DynamicSpline class that you're importing. https://www.learnpyqt.com/courses/adanced-ui-features/creating-multiple-windows/
why does this line selected_device = tk.StringVar() give me the following error?
Could you post more of your code?
the code is a bit messy but I'll try to give some context, basically, I'm using the sounddevice library for a device recorder I'm making, and right now I'm trying to make an OptionMenu that allows you to select which audio device to record from
I looked at the code in the tkinter lib and it seems to be a problem regarding the tk.StringVar() constructor itself
but idk what to do, all examples I've found online just do tk.StringVar() and it works fine
Yeah, that's why I'm wondering if something else in the code is making it be wonky
!paste you can also use the pastebin
Pasting large amounts of code
If your code is too long to fit in a codeblock in discord, you can paste your code here:
https://paste.pydis.com/
After pasting your code, save it by clicking the floppy disk icon in the top right, or by typing ctrl + S. After doing that, the URL should change. Copy the URL and post it here so others can see it.
import keyboard
import sounddevice
import tkinter as tk
def change_hotkey():
keyboard.remove_all_hotkeys()
hotkey = keyboard.read_hotkey()
keyboard.add_hotkey(hotkey, record_audio)
field_hotkey.config(text=hotkey)
def record_audio():
print("test")
device_list = sounddevice.query_devices()
selected_device = tk.StringVar()
hotkey = "ctrl+q"
keyboard.add_hotkey(hotkey, record_audio)
root = tk.Tk()
root.resizable(0, 0)
root.title("Epic brown shapiro sampler!!!")
canvas = tk.Canvas(root, width=256, height=256)
canvas.pack()
icon = tk.PhotoImage(file="brownicon.png")
root.tk.call("wm", "iconphoto", root._w, icon)
background_image = tk.PhotoImage(file="background2.png")
background_label = tk.Label(root, image=background_image, )
background_label.place(relwidth=1, relheight=1)
label_hotkey = tk.Label(root, text="Hotkey", fg="white", bg="#60676d", anchor="w")
label_save = tk.Label(root, text="Save Loc.", fg="white", bg="#60676d", anchor="w")
field_hotkey = tk.Label(root, background="white", text=hotkey)
field_save = tk.Label(root, background="white")
button_hotkey = tk.Button(root, text="Change", command=change_hotkey)
button_save = tk.Button(root, text="Change")
label_device = tk.Label(root, text="Audio Device", fg="white", bg="#60676d", anchor="w")
menu_device = tk.OptionMenu(root, selected_device)
label_hotkey.place(relwidth=0.3, relx=0.05, rely=0.2)
label_save.place(relwidth=0.3, relx=0.05, rely=0.3)
field_hotkey.place(relwidth=0.35, relx=0.35, rely=0.2)
field_save.place(relwidth=0.35, relx=0.35, rely=0.3)
button_hotkey.place(relwidth=0.2, relx=0.75, rely=0.2)
button_save.place(relwidth=0.2, relx=0.75, rely=0.3)
label_device.place(relwidth=0.3, relx=0.05, rely=0.45)
menu_device.place(relwidth=0.35, relx=0.35, rely=0.45)
root.mainloop()
HA. Okay
Move root = tk.Tk() to the very top (but below import statements) above the tk.StringVar()
I always wondered if that was the case and this proved it
oh also, is there a way to change the visual aspects of an OptionMenu widget?
- text anchoring and what not
actually, nevermind, I'm gonna migrate to pyqt instead
seems much better than tkinter overall
I have a problem with a stubborn QWidget inside a scrollArea. It doesn't want to take up it's minimum amount of space. I've tried setting size policy to minimum, set minimum height to 0, but nothing seems to work. Any ideas? (I'm working in PySide2)
have you tried scrollArea.setWidgetResizable(True)?
Yes
This is with scrollArea.setWidgetResizable(True) and green is the widget's background color
And here it is with scrollArea.setWidgetResizable(False) and red is the scrollArea's background
So that leads me to think it is the scroll area that makes the widget scale up to fit the scrollarea
So what behavior are you looking for?
I basically want it to be the exact length of it's content
It shouldn't be taller than the two bars named "Name Editor" and "Settings" combined.
If I unfold one of the bars, it does get the exact length. It's just that it can't go small enough.
Here is with one of the bars unfolded. And it doesn't force the scroll area to be a tiny bit too long
So the scrollArea should always be the same height it is in the red/green screenshots?
No the scroll area should never force the window taller. The scroll area should be as long as the window height allows it. But when I scale the window down to it's minimum height, there shouldn't be any extra green/red at the bottom.
Basically the problem is that the scroll area won't scale down enough vertically. It forces an extra about 28 px even though the minimum height is set to 0
try setting it to 1
Alright 2 sec
wait
?
whats the sizePolicy?
Minimum, minimum
vertical
On literally everything
try setting vertical to Preferred
If I set the minimumHeight to 100, it scales up to 100px, but it won't go lower than 48 pixels
Okay
Setting it to preferred allows me to scale it down to 0, but it doesn't initialize in minimum size
what is the minimum height on the Widget that you used for scrollArea.setWidget(Widget)?
it's also 0
And set to minimum, minimum
this is with preferred, if I scale it down as much as possible
But this is what it looks like when initialized
And I want it to look like this when I open it, and I don't want it to be able to be scaled shorter than this. But it needs to be able to scale taller.
Could someone help me out with this? I have been trying to pull the information from the entry fields and place them into a list for later use. Best I have been able to do is just pull the last field.
https://paste.pythondiscord.com/jeqafehubi.rb
I've been beating my head against it for 2 days
Can you post the code for the expanding group boxes and scrollArea?
I can't post the code for the expanding group boxes because I call their creation in Autodesk Maya. It is not something I have written myself.
I basically create them using Maya's own scripting language and then grab the Qt object after creation and work with that
But here is for the scroll area, and I apologize for it being messy I've just been throwing stuff at the wall to see what sticks ```python
self.scrollAreaLayout = QVBoxLayout()
self.dropdownLayout = QVBoxLayout()
self.dropdownLayout.setSpacing(0)
self.dropdownLayout.setMargin(0)
self.nameEditorContainer = QVBoxLayout()
self.extraSettingsContainer = QVBoxLayout()
self.dropdownLayout.addLayout(self.nameEditorContainer)
self.dropdownLayout.addLayout(self.extraSettingsContainer)
self.nameEditorContainer.addWidget(self.editorWidget)
self.extraSettingsContainer.addWidget(self.extraSettingsWidget)
self.dropdownLayout.setStretchFactor(self.nameEditorContainer, 0)
self.dropdownLayout.setStretchFactor(self.extraSettingsContainer, 1)
self.scroll = QScrollArea()
self.scroll.setMinimumHeight(1)
self.widget = QWidget()
self.widget.setStyleSheet('QWidget {background-color: green;} QVBoxLayout {background-color: blue;}')
self.widget.setMinimumHeight(1)
self.scroll.setSizePolicy(
QSizePolicy.Minimum,
QSizePolicy.Preferred
)
self.widget.setSizePolicy(
QSizePolicy.Minimum,
QSizePolicy.Minimum
)
self.widget.setLayout(self.dropdownLayout)
self.scroll.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
self.scroll.setWidgetResizable(True)
self.scroll.setWidget(self.widget)
print(self.scroll.sizeHint())
self.mainLayout.addLayout(self.scrollAreaLayout)
self.scrollAreaLayout.addWidget(self.scroll)
self.mainLayout.setStretchFactor(self.nameLayout, 0)
self.mainLayout.setStretchFactor(self.settingsLayout, 0)
self.mainLayout.setStretchFactor(self.scrollAreaLayout, 0)```
Okay the indentation messed up a bit
@eager beacon Okay this is odd. I set the minimum size to 44, which is apparently the height I want it at. And then I added a self.adjustSize() right after self.setLayout(self.mainLayout) and it fixes the issue. If I set the self.adjustSize() before the setLayout or after I add he scrollArea it doesn't work.
oh
well in that case couldn't you use scrollArea.setSizeAdjustPolicy(QAbstractScrollArea.AdjustToContentsOnFirstShow)
the base policy ignores size adjustments
I'll try
I have a new problem though
Window doesn't get automaticly longer when I unfold one of the bars anymore. It used to force the scroll area and window taller
Maybe that is the size policy?
Minimum will do that
The setSizeAdjustPolicy didn't work
might try AdjustToContents then
it will adjust anytime the scrollArea viewport changes
Just tried, didn't work
It doesn't change at all
Unless I manually resize the window
Not sure how I fucked it up
Do you know the size of your group boxes when expanded ahead of time?
I will when they are done
you could just change the sizeHint then
I'd have to do that dynamically when I open and close them?
yeah. you could emit the size, or something else, depending on how you wanted to do it
How do I set a size hint?
scroll.sizeHint = lambda s=QtCore.QSize(400,200):s should work since you aren't subclassing the scrollArea
or you could define a normal function and assign that as the sizehint
doesn't really matter, it just needs to be a function that returns a QSize
It works
what does
The command to change sizeHint
But how will changing the size hint make the scroll area get the right size?
If I adjustSize() it jumps back to that weird spot it has always wanted to be in
you can try updateGeometry instead
but why do you even need adjustSize if the sizeHint is working?
Oh I mean it's literally changing the number
Not that the window is actually following those sizes
hm, if you change a sizeHint and then explicitly call updateGeometry the size of the widget should be updated
It updates horizontal, but not vertical
check the sizePolicy for vertical
I changed it back to minimum
Should it be preferred?
Welp, doesn't make a difference
can't you remove the policies if you're setting the sizeHint?
Sure let me give it a shot
No difference
I've tried setting it to scale to 1000 px vertically on updateGeometry and it's like "Nah boi"
is the widget containing the scroll area enforcing a maxHeight or something else?
Only minimum height
maybe a Maximum SizePolicy
This is all the things I call on self.scroll
What the fudge is it about QScrollArea that wants to be 74 pixels tall
pretty sure thats the combined sizeHints of your boxes within
Let's figure it out
+- any contentsMargins on layouts or widgets
how tall is a collapsed widget?
the group box thing you have
They're 44 together, so 22 individually
sizeHint for the boxes are 75 wide and 22 tall per group box
have you removed all of the contentsMargins on widgets and layouts?
setContentsMargins
Ah, let me try
scrollLayout too
Aight, gimmie a sec
You can also apply it to the widgets, but I'd think that would be taken care of by the qss
Okay I think I have found a mistake
I think I've made some kind of mess up between self.scrollAreaLayou and self.dropdownLayout. I need a minute or two to figure out wtf I've done
Thanks for all the help Chris
speaking of GUIs - is there any logic behind Star Treks LCARS displays???
@eager beacon sadly I'm gonna have to go catch some Z's, but I've hooked up functions on expand and collapse for both of the bars and then I hope to get current size of the window and add or subtract the height of that group box. And we'll see how that works. Thanks for all your help, it is much appreciated. π
Could someone help me out with this? I have been trying to pull the information from the entry fields and place them into a list for later use. Best I have been able to do is just pull the last field.
https://paste.pythondiscord.com/jeqafehubi.rb
I've been beating my head against it for 2 days
def create_list(self, event):
#self.text= tk.StringVar()
for x in self.data_needed:
self.text = self.ent.get()
self.input_data.append(self.text.get())
print(self.input_data)
#creates input fields
def makeform(self, user_data_info_frm, data_needed):
for y in self.data_needed:
self.row=tk.Frame(self.user_data_info_frm)
self.lab=tk.Label(self.row, width=15, text=y, anchor='w')
self.ent=tk.Entry(self.row)
self.input_data.append(self.ent.get())
self.row.pack(side=tk.TOP, fill=tk.X, padx=5,pady=5)
self.lab.pack(side=tk.LEFT)
self.ent.pack(side=tk.RIGHT, expand=tk.YES, fill=tk.X)```
I've tried a ton of solutions I found, but I can't get the entries into a list
I don't know much about TK, but is this intentional?
self.text = self.ent.get()
self.input_data.append(self.text.get())
Do you really need to call get twice on the same object?
alright, just asking, because I really don't know much TK
I've gone through at least 30 different iterations of the makelist function
I can get it to pull the last field, but not any of the others, so it is not looping through the entries
in makeform, or create_list?
The makeform is working, but that's where the entries are. I'm using the create list to build a dynamic list
I've probably messed it up more trying to fix the createlist function to work like I want it
How are you going to get text from entries that you have no reference to?
Might be my issue, I've tried a lot of things and probably deleted them.
I'm only two weeks into learning python so it could be something as simple as that
for x in self.data_needed:
self.text = self.ent.get()
self.input_data.append(self.text.get())
You only have x as a loop variable and do not use it
def create_list(self, event):
for x in self.input_data:
self.text = x.get()
print(self.text)
that seems to work
You only have self.ent to query and it is not going to change
Awesome, thanks y'all! I'll give that a go.
input_data will only contain the text the entries were created with
so a bunch of empty strings
you will need to store the references to the entries themselves in a list and call .get on them for create_list
something like
def makeform(self, ...):
self.form_entries = []
for i in self.data_needed: #why is it both a self attribute and a parameter?
...
ent = tk.Entry(self.row)
self.form_entries.append(ent)
...
then you can run through all the entries in create_list, but you may consider using a dict instead of a list if the order is going to change in any way
Thank you, I'll dig into this now. Thank you so much!
@amber roost @eager beacon between the two of you all, that got it! Thank you!
hey i have a problem with PyQt i am using the Qt designer when i try to apply Qscroll bar customizations
it shows as its applied but in the preview window it reverts back to the default style
thinking it might be a visual glitch i saved the ui file as a.py file and tried to launch up the main window
but the customization still doesnt show
how do i fix this?
Can somebody help with Tkinter and the after function
I'm trying to make a while loop but using the after function
I have programmed a lot in Python, but never worked with any GUI libraries. I have done some in Java with JavaFX. What I'm wondering is what would be good choice for me to start working with in Python?
Alright, great. I will check these out. Thanks!
hey i have a problem with PyQt i am using the Qt designer when i try to apply Qscroll bar customizations
@bronze basin This is for the widget QTextBrowser just in case that helps to solve the issue i am having or smth
Can I somehow add a black line between the item header row and value row? Pic related. Also how can I turn a cell value into a multirow string?
I'm building a PySide2 application inside Autodesk Maya. It is built in a QDialog and have some unfolding content that on unfold resizes the window to make space and I had it working as intended until I set my class to inherit from mayaMixin that adds the widget to another QWidget that can dock inside the Maya UI. Any ideas how I can get the new mayaMixin QWidget to resize like I did my QDialog, because it doesn't seem to respond to any kind of resize function.
Thinker or kivy?
@ruby pawn Did you ever get your scrollArea working?
Yes @eager beacon , I got it to work by resizing the window.
Calculate the desired size and then resize.
glad to hear it
Hi! Im working on a simple web app with python and django and i need to decide which frontend framework i will use, i have never worked with fronted libraries or frameworks before, which one is the most easy and quick to learn?
You'd probably get better responses if you asked in #web-development
Ok, thanks!
Would anyone know how to create a nested layout with QBoxlayout. I am trying to make a button when pressed that opens up a calculator. The problem with this and I do not know how to make another popup.
I am running into an issue that I cannot create another QVBoxLayout
Whats stopping you from doing that?
let me grab the error code hold up
okay
is it the one that says you cant add a layout to a widget with a layout?
or something like that?
you're using setLayout to get that error?
yeah
try addChildLayout
ohh bet. give me a second
are you trying to get the calculator to appear in a new window or in one of the columns in the screenshot above?
in a new window
I haven't actually. What widget?
Oh i see, okay let me see if the addChildLayout is going work. I deleted the code so gimme a second
sure
@eager beacon
def showBox(self):
layout = QVBoxLayout()
layout.addWidget(self.c)
layout.addChildLayout(layout)
wait
I have to addChildLayout to the original layout
l1 = QVBoxLayout()
row1 = QHBoxLayout()
l1.addChildLayout(row1)
you would add rows of buttons to the row layouts
oh I see. but Still nothing pops up when I click my temporary button which calls showBox(self)
use a dialog?
I added a print statement and the button is calling the function
I'll be honest very new to Python so I am not sure what exec_() even is
its a method of the QDialogue
!paste
Pasting large amounts of code
If your code is too long to fit in a codeblock in discord, you can paste your code here:
https://paste.pydis.com/
After pasting your code, save it by clicking the floppy disk icon in the top right, or by typing ctrl + S. After doing that, the URL should change. Copy the URL and post it here so others can see it.
oh wow
so yeah this is controlling what I call the bottom bar of the program
Temporary button which is calling my showBox function
ok
so in showBox you need to create a widget
then set a layout on that widget
that would be the vBox
then add hBoxes to the vbox with addChildLayout
but I'd still argue that you should go with a grid layout
its entire purpose is to do what you want to do
def showBox(self):
print("T")
l1 = QVBoxLayout()
row1 = QHBoxLayout()
c1 = QPushButton("c", self)
l1.addWidget(c1)
l1.addChildLayout(row1)
Yeah that still doesn't work for some reason
I also agree with you. Once I get a popup I'll switch
I notice addChildLayout is part of the QLayout class. Would that have anything to do with it
Holy hell that worked
you cant view a layout without a widget to contain it
That makes so much sense
@eager beacon I bestow upon you a cookie, as gift for your time and effort. πͺ
anyone brave enough to test a tiny wxpython script/app i've put together? i just want to see if any major errors happen on different kind of systems
hello, is this the right channel for tkinter questions?
hey how to add amzing gui to pyqt
like the ones in qt designer are stock designs
how to add our own designs
if u have answer pls dm me
hey guys, how do you make modern looking GUIs in pyQt5
and is there a way to add dynamic images
@gaunt saffron yes there is through learning and getting good at design
also if you mean gifs yes you can add gifs
@bronze basin I mean like any modules that I could use. And by dynamic images i mean like dynamic wallpapers that move based on user interaction.
maybe you would use Qpainter for that but not entirely sure
does anyone know what specs do i give a virtual machine to run linux?
@digital rose that's not python related or user-interface related. Give it the minimum required unless you're planning on running something that requires more resources. It's a VM, you can always recreate it or allocate it more resources later.
there isn't really a proper channel for a non-python question on a python server. Maybe off-topic? But again, just give it the minimum required and get on with it.
ok...... :)))
anybody who works with wxpython have any tips for speeding things up/getting smoother rendering results for things like resizing your window and stuff? i'm working on an image viewer and it's going well but repainting a large image during any frame resize events is kind of stuttery
i thought that this is related to UIs and OSs so i asked.......
The channel topic: "For help relating to Python User Interface libraries (e.g. PyQT, Tkinter, WxPython, Curses, PySide)"
Setting up a linux VM does not fit that channel description
sorry........ π¦
@real parcel are you using double buffer?
@static cove it didn't seem to help. idk
it's weird; like the graphics of the window appear to be ghosting while the window is resizing
i'm sure i'm doing something wrong but i dunno what. what should i be sure i'm doing in the paint event?
to clear the background i mean
i'm guessing that's the issue
like, that the background isn't clearing properly or fast enough
oh wait ALL my windows in xfce are like that, lmao π
in tkinter: .grid or .pack?
yeah it looks way better in gnome3. lmao π
@digital rose I prefer grid, but usually end up using a combo with frames to prevent space manager conflicts
@static cove do you possibly know how buttons in tkinter work?
what do you call this window?
is is just a popup window?
I want to create a popup window like that which is linked to the main window as you can see in pyqt5
Is anyone online willing to help me with a PyQT5 Qgridlayout() question? I'm getting some funky behavior.
whats the problem?
@normal plinth
@spark furnace thats just a widget that contains a tabWidget and a lineEdit
Basically, every element is showing at position 0,0.
did you specify row/col positions?
I did, 0, 0 through 0,6 but they all stack on top of each other at 0, 0.
When I comment them out, they all show in the same position 1 by 1.
This is the gist
you need to call self.setLayout(self.grid)
you are only seeing them because you assigned Window as the parent of the buttons'
if you removed the self argument from the buttons they wouldnt even be visible
When I do that, I'm getting an error "QWidget::setLayout: Attempting to set QLayout "" on Window "", which already has a layout", but you've definitely made it easier for me to diagnose.
Thank you Chris! You should start a YT channel and a Patreon, lol
hah
You are using a mainWindow
and it has whats called a centralWidget
so you need to set a centralWidget
then set a layout on that widget
and add things to that
instead of directly to the mainWindow
Okay, so my layout grid will be contained inside the central widget, which will be contained in the main window.
exactly,
w =QWidget()
self.setCentralWidget(widget)
sets the centralWidget
if any1 is listening PLZZZZ HELP ME OUT...i need to know how to correctly embedda pie chart in tkinter gui and update its values on the run with a button.PLZZZ HELPπ’ π’
plz dm if possible
@eager beacon But how do you make the widget popup
connect the buttons clicked signal to the widgets show()
that one is popping up right above the button it looks like
so they are also mapping a position to have it appear in that position
I'll reading up on the mainwindow/central widget to see how best to structure it. Thanks for the help!
@spark furnace hide the widget and when something happens show it?
or make a new window in case you need to use the space in which the popup will show
hi does anyone know if tkinter message boxes work in python 1.8.3
on every documentation site if have seen it says they are a thing
Im getting an error that basically is saying they dont exist
@leaden tiger I do mostly, are you having an issue with buttons?
Hey guys, I have some problem with my PySide2 application messing up when I dock it in Autodesk Maya. Any helpful tips to figure this out?
How many of the AUTO bars should be visible?
@ruby pawn I've seen similar things happen to widgets if you have a minimum width or height larger than the maximum
It's supposed to look like this
But it also makes this bug
Can it be because the minimumHeight is shorter than sizeHint height?
sounds plausible but I'm not positive one way or another
I'll give it a shot in a moment
If that is indeed the problem. I guess the damn scroll area strikes again
is the gap on the right side happening because that where the vertical scrollBar is?
Which gap?
Maybe maya has some weird dockWidget policies
like, nothing goes out to the edge
And they rewrite the .show() command
its like there is a scroll bar there but its been hidden but not removed
To create a new widget that they slam your UI into
This is what it looks like with a scroll bar btw
Anyway. I have posted on the Maya Programming forum, to see if any of those people have an idea what I've done to misplease the Maya Gods
yeah, Nuke does the same sort of stuff and it also enforces arbitrary rules for some things that can't be modified by the user
If I mouse over anything button that has a :hover stylesheet thing, it redraws the button in the right place. Like wtf
oh
Thank god I've only ever had to do a few yes/no dialog boxes in Nuke
try calling update or repaint then
On which widget
I don't even know which one is the container anymore
Like after doing the maya docking
hah
It puts the QDialog into a QWidget
That has a QSplitter above it
That has a QTabWidget above it
That has, another freaking QWidget above it
gotta have a pretty property panel!
update calls repaint
I have found an event call that happens most of the times I dock it, it doesn't seem 100% reliable but oh well
so w/e
maybe you can save and restore the geometry?
timer on the repaint? I'd just do it on w/e signal fires when docking or undocking]
since that's when the issue appears
Alright I've tried to call updateGeometry() on all QObject from QDialog and up
Nothing changed
did the repaint work?
I'm assuming thats whats triggering the update as you mouseover and the enterEvent is fired
Oh I can try repaint()
2 sec
Nope
No luck
Destroying the UI and doing .show() again does fix the issue
Or resizing the window fixes it
But I can't seem to do it with code
calling resize manually doesn't change it?
Maybe I'm not trying to resize on the right widget
just for the sake of testing start on the inner most widget and if it has children resize them otherwise resize the widget
then move on to its parent and to the same thing
resizing widgets to the current size would probably be fine
or start with the thing that inherits the mixin and resize all of its children and childrens children
Okay here's a weird thing, if I repaint on a button click. It fixes everything but the scroll area
Like wut
Oh my god
It literally is the scroll area fucking everything up
If I don't have the scroll area, no bugs what so ever
Or well no I'm being an idiot. Sorry.
It's the maya expansion thingies
The maya expansion thingies inside the scroll area is doing it
I'll try to add them back but remove the scroll area to confirm
Yup
It's the fucking maya group box things. FUCK
I will find another solution than the weird group boxes. Thanks for your help troubleshooting again @eager beacon it is much appreciated as always
@static cove yes, i am using the buttons by importing an image by path over an object. i want after a click to change the image, is that possible?
Click in a specific spot or just a click in general?
@kutiekatj, just click in general. i programme my first python programme in python and tkinter. its a card game. i can send you the code what i am doing to import the image?
@ruby pawn you might try throwing this into Maya to see if it behaves correctly https://stackoverflow.com/a/52617714
its a similar situation to what you have going on with scroll area contained in a dock
you might have to throw a verticalSpacer in under the scrollArea to get the behavior you want though
This is creating a collapsible box from scratch no?
yes
@leaden tiger So you want to look into bindings then. https://effbot.org/tkinterbook/tkinter-events-and-bindings.htm
You can find a function to the user clicking in a window. That function can then change the picture.
Thanks for the resource, but I don't think I want to bother creating my own collapsible boxes. I was only using them to stay within the maya design language. If necessary I'll find another way of containing more options while keeping the UI footprint small. Such as tabs.
you could also consider using collapsible layouts instead of a resizing the widget
@static cove do you mean command binding?
Maya uses these tabs, so that is my back up plan.
But I found out that the issue with the collapsible box is the way I add content to them. Apparently getting the Qt object, querying the layout and adding a widget is not okay with Maya.
I don't remember where I stole this from but I've used it in place of what you're doing before and didn't run into any of the issues you've seen
Or I might go with menuItems.
@leaden tiger yes, you can bind the user pressing their mouse or specific keys to a specific command and the command can be a function you write.
@static cove i have already done that ... my problem is the following
global playerTwoCard1
newcard = stack.pop()
img = Image.open(newcard.bgpath)
img_resize = img.resize((150,300),Image.ANTIALIAS)
newimage = ImageTk.PhotoImage(img_resize)
playerTwoCard1 = Button(root,image=newimage,command = lambda: player2click(1))
playerTwoCard1.image = newimage
playerTwoCard1.grid(row=0,column=0)
how do i get the newcard.bgpath to newcard.imgpath after a click?
the tabs might be an okay solution if you don't need to constantly swap between them to use your plugin
Oh no, it'll be like once in a blue moon
sounds like that might be the way to go
Problem with tabs is the height of the app is defined by which ever tab that is tallest
I did write some code that auto resize them but.. It wasn't amazing
I had to make some shelf things for Maya a couple of years ago and it was a pain so I get where you're coming from
So I might make a main window and add menu items where you can switch the widget in the main window
I'd say just go with the easiest solution at this point
sounds reasonable
I was supposed to do a pipeline internship at a VFX studio
But the studio is dissolving
but so did the collapsible boxes lol
So they just let me do my own shit
are you in LA?
No, Copenhagen
ahh, all of the VFX work over here is pretty much exclusively in LA and they don't like people working remotely but if they did I'd love to be a TD
A few people I know went to LA
Mostly animators though
But most people here do London or Copenhagen
makes sense. London has a bunch of studios
@leaden tiger I don't see the code that captures the user clicking
Oh we're definitely filling up this chat, I feel bad
@static cove it should look like this for the first card
def player1click(chosen_card):
global round
global stack
global playerOneCard1
if chosen_card == 1:
playerOneCard1.grid(row=1,column=1)
if round == 3:
newcard = stack.pop()
img = Image.open(newcard.imgpath)
img_resize = img.resize((150,300),Image.ANTIALIAS)
newimage = ImageTk.PhotoImage(img_resize)
playerOneCard1 = Button(root,image=newimage,command = lambda: player1click(1))
playerOneCard1.image = newimage
playerOneCard1.grid(row=2,column=0)
elif chosen_card == 2:
playerOneCard2.grid(row=1,column=1)
if round == 3:
newcard = stack.pop()
img = Image.open(newcard.imgpath)
img_resize = img.resize((150,300),Image.ANTIALIAS)
newimage = ImageTk.PhotoImage(img_resize)
playerOneCard2 = Button(root,image=newimage,command = lambda: player1click(2))
playerOneCard2.image = newimage
playerOneCard2.grid(row=2,column=1)
elif chosen_card == 3:
playerOneCard3.grid(row=1,column=1)
elif chosen_card == 4:
playerOneCard4.grid(row=1,column=1)
elif chosen_card == 5:
playerOneCard5.grid(row=1,column=1)
round = 1
@static cove but i am thinking about to skip playervsplayer and just write a random card for playervscomputer and dont change backgrounds
@static cove but when the computer plays a background card i need to switch the bgpath to imgpath too ... so no difference
@static cove i am looking for something like playerOneCard1.method(object.value) ... does something like this for a button exists?
or is it better to programme that with pygame?
because i have also recognized, that the code stops running after clicking and dont get back to the function before?
in pyqt5, how do i hide a specific menu item; not a whole menu, but one item in it
does anyone know how to make it so you dont have to use a button to print a listbox selection
I bound my function to mouse1 and it does work
but when I use a button somehow it magically does
@dark gulch can you share the code where you bind mouse1?
is there a way to install pyside2 on Python 3.8?
It should work for 3.8
let me try again, since I last tried 2 weeks ago
pyside version5.14 definitely works for 3.8, but you should make sure you have at least python 3.8.1+
The last release of it was Sept 10, so nothing would've changed since 2 weeks ago
How are you installing it and what OS?
Iβve only tried on a repl, which gives me a forbidden error for the version.
The specific version on the repl is 3.8.2.
would it work on Windows 10 python 3.8.5?
Huh, I don't use repl much. It should work though with win10 and 3.8.5
also, is Qt Creator also available (for .ui) on PySide2?
thereβs not much I can find unless it comes with the normal Qt Creator.
I don't use Qt Creator much, but the .ui should work with PySide2
Huh, looks like it's an issue with poetry/repl.it
Repl.it is specifying for python versions ^3.8, but that means every python version >= 3.8 and <4.0. Pyside2 doesn't work for 3.9 yet
So poetry can't resolve the dependency
Repl.it should probably be using the notation of 3.8.* to get that not to break since 3.9 is so new
oh it isnβt a problem then, I can always finish, and except name errors so I can test on the repl first.
Curious. That could probably be an improvement on poetry's part
It's a bit unintuitive to me that ^3.8 would include 3.9
yeah it installed successfully. but are the .ui files generated from Qt Creator for Python same as the CPP ones for pyside?
i mean does pyside2 read the same files as ones made with the CPP qt creator?
There could be some slight differences but it shouldn't be anything visible to a user
@static cove
import tkinter as tk
root = tk.Tk()
root.geometry("400x240")
listbox = tk.Listbox(root)
listboxitems = ["Mass", "Volume", "Area", "Height", "Width", "Length"]
listbox.insert(1, "Length")
listbox.insert(2, "Width")
listbox.insert(3, "Height")
listbox.insert(4, "Area")
listbox.insert(5, "Volume")
listbox.insert(6, "Mass")
listbox.pack()
def SelectFunction():
selection = listbox.curselection()
print(selection)
root.bind('<Return>', SelectFunction)
# submit = tk.Button(root, text='Submit', command=SelectFunction)
# submit.pack()
root.mainloop()
Sorry for responding so late
the button works fine
but when I bind the function to mouse 1
I get this
@dark gulch Change the function definition of SelectFunction to:
def SelectFunction(*args):
Depending on which key you bind it'll pass additional information you can use to what's attached as the callback. You need to make sure you account for it and catch it
The mouse click will pass the coordinates of where the user clicked as an example
*args will catch anything it passes and put it in a tuple for you to use
@static cove may i ask you ... any idea?
@leaden tiger Did you check out the link I gave you about bindings and events in tkinter? Your code isn't tracking when a user clicks anywhere, only when they click the button
@static cove thanks so much I was just staring at it for like 2 hours not knowing what to do
@static cove i read your link, but the binding is like the command which i give on button creation and i still dont know how to access the value of the object in the button
So I think I'm not fully understanding what you want to do. I thought you wanted to change the picture of some element in your window when the user clicks anywhere their mouse
@static cove nope
wait does pyside2βs license allow creating public applications?
@static cove not to be a bother but how would I use the indices of the selected string in a something
if selection == "(0,)":
selection = "Length"
if selection == "(1,)":
selection = "Width"
if selection == "(2,)":
selection = "Height"
if selection == "(3,)":
selection = "Area"
if selection == "(4,)":
selection = "Volume"
if selection == "(5,)":
selection = "Mass"
I tried this and its weird
It just prints the same stuff
@static cove i assigned a object from a list to a variable, that variable contains the background and foreground path to images ... i set the foreground path to the button and it shows me the button with the picture but i want to change the foreground to the background ... therefore i need to access the object within the button
@static cove maybe with an image its better to understand
are you making a card game?
@dark gulch yes π
what game?
its called schnapsen
no, its spreaded around in our country
your from austria correct?
yes
@leaden tiger from what you typed the button only contains the path to the foreground image. It doesn't contain the object with both the foreground and background
Thats cool that its the "national card game". Weird but cool
@dark gulch where is the "(1,)" coming from? What is selection specifically?
@static cove ok? how do i need to reprogramme that ... so i can change background and foreground card?
just a second, i give you my code
well curselection assigns selection to the indices of the list box so I thought it would just be a string and I could simply convert it back
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
@dark gulch just try:
if selection == (4,):
no quoted around the specific thing you're checking against
I did but I will try again
Nothing just prints it out
wait
On this site it says it returns a list
so the (5,) is a list?
(5,) is a tuple
ahhh
@leaden tiger currently on my phone so it's a bit tough to read that much code. Is it cool if I take a look at it in the morning and get back to you?
@static cove sure, no problem π ... i set the paste for 1 hour, so just write me if you have time and i send you the code again?
@dark gulch when you do selection = "Length" what are you trying to do there?
@leaden tiger yeah, I'll ping you tomorrow
Reassign what it prints to Length
@static cove idk, if pygame is better for creating card games, because i have seen some on their website
@leaden tiger I think it'd be worth checking out. I think it handles images better than tkinter
In theory when I click on one of the listbox inputs it will come out as what is clicked
@static cove yeah, thats the point ... i need buttons to click and the code does not run in a while loop π¦
@dark gulch so you're effectively printing .curselection() right now?
I got it to work @static cove For some reason when I did
global selection
so I just put the entire thing inside the fuction
and it works
Try this:
your_listbox.get(your_listbox.curselection())
And print it
But this works
Ill try that
I was trying that earlier
I dont think listbox.get is a thing
That'll prevent you from writing the 'if selection == (5,):' thing
oh
wow
I guess I was just writing it wrong bc I tried to do this earlier bc I knew it would work bc for every other widget it did
Thanks
anyone have decent experience with Automating Windows Applications Using COM
I am able to access the aplications library fine and call any of the methods i want, problem is i want to call that as fast as humanly possible, and right now it takes like 20 seconds to call them all and i cant start the next cycle till the first finishes
does PySide2 legally allow public applications?
@static cove i managed changing the foreground and background image with pygame ... i think i will get into pygame to create the game π