#user-interfaces
1 messages · Page 73 of 1
you could use parent and children
class Design(App):
def __init__(self, **kwargs):
super(Design, self).__init__(**kwargs)
self.main_hero = MainHero() # Tried main_hero = MainHero() too
self.val = StringProperty(self.main_hero.nick)
``` isn't how you use props
```py
class Design(App):
val = StringProperty()
def __init__(self, **kwargs):
super(Design, self).__init__(**kwargs)
self.main_hero = MainHero() # Tried main_hero = MainHero() too
self.val = self.main_hero.nick
if you want to
use electron.js with html and css
or you can use html, css, and python eel
or you can use Qt, Kivy, and other frameworks
ok
If you want to go classic, you can use python and tkinter too
this isn't working I tried
def rename(self):
# self.app.main_hero.nick = "Renamed"
self.app.val = "Renamed"
Or move the Prop
@coarse mirage use a style sheet
@coarse mirage ```
/* LBT_PSB_groupsearch */
QPushButton#LBT_PSB_groupsearch{
background-color: $ui-01;
color: $link-01;
border: 1px solid Transparent;
border-radius: 2px;
background-image: url(':/icon_pack/png/16/search_icon-02.png');
background-position: center;
background-repeat: no-repeat;
}
QPushButton:disabled#LBT_PSB_groupsearch{
background-color: $disabled-02;
color: $disabled-03;
border: 1px solid Transparent;
border-radius: 2px;
background-image: url(':/icon_pack/png/16/search_disabled-02.png');
background-position: center;
background-repeat: no-repeat;
}
QPushButton:hover#LBT_PSB_groupsearch{
background-color: $active-ui;
color: $hover-primary-text;
border: 1px solid Transparent;
border-radius: 2px;
background-image: url(':/icon_pack/png/16/search_icon-01.png');
background-position: center;
background-repeat: no-repeat;
}
QPushButton:checked#LBT_PSB_groupsearch,
QPushButton:pressed#LBT_PSB_groupsearch {
background-color: $active-ui;
color: $hover-primary-text;
border: 1px solid $ui-01;
border-radius: 2px;
background-image: url(':/icon_pack/png/16/search_icon-01.png');
background-position: center;
background-repeat: no-repeat;
}
ok
How does one apply a QLinearGradient to a QTabWidget tab. I tried ```py
self.main_background_gradient = qtg.QLinearGradient(0, 0, self.width(), self.height())
self.main_background_gradient.setColorAt(0, qtg.QColor("#30cfd0"))
self.main_background_gradient.setColorAt(1, qtg.QColor("#330867"))
self.main_background_gradient_brush = qtg.QBrush(self.main_background_gradient)
self.main_background_palette = qtw.QApplication.instance().palette()
self.main_background_palette.setBrush(qtg.QPalette.Base, self.main_background_gradient_brush)
self.notebooks_tab.setPalette(self.main_background_palette)
the self.notebooks_tab is the widget assigned to one of the tabs on the main QTabWidget
anyone who is familiar with qt designer can help me? i want to change the colour of main window but not the tool bar
Hi
im currently working on a TKinter maze game
im trying to get my restart button to work
but it doesn't want to
anyidea how i can do this?
i need it to destory the canvas than
start the program from the beggining
rn it destorys canavs
idk how to make it start the whole code again
i can't have it in a whole new function i think im not sure
Thanks
any help with this pls
i would recommend posting your code
that way someone has an idea of what your doing
Hey @queen mist!
Uh-oh! It looks like your message got zapped by our spam filter. We currently don't allow .txt attachments, so here are some tips to help you travel safely:
• If you attempted to send a message longer than 2000 characters, try shortening your message to fit within the character limit or use a pasting service (see below)
• If you tried to show someone your code, you can use codeblocks
(run !code-blocks in #bot-commands for more information) or use a pasting service like:
anyone?
You can edit the stylesheet of the mainwindow
background-color: blue
yes found it already but thanks
can anyone help with this?
restart button
code above ^
is curses in python system independent?
is this correct?
Hey @open lintel! I noticed you posted a seemingly valid Discord API token in your message and have removed your message. This means that your token has been compromised. Please change your token immediately at: https://discordapp.com/developers/applications/me
Feel free to re-post it with the token removed. If you believe this was a mistake, please let us know!
@hushed night Why so :0
There not that was random
Cool thought 😄 @hushed night
😂
Anyone know how to identify what subplot you are accessing during event handling in matplotlib/pyqt?
So if you have a click event and a 6x2 subplot figure. How could one determine which subplot is being clicked on?
What kind of objects are these plots, find that out. Use type() . If it is actually of some tkinter widget, then w.winfo_containing(rootX,rootY,displayof=0) might be of SOME help
well I found a roundabout way. If I loop through my axes_list, I can figure out which index its in, by checking each axes_list[i] == event.inaxes.
For some reason np.where(event.inaxes==axes_list) always yields no return
Thought that was kinda odd.
Im just working with the standard pyplots though
Do you want the entire treeview's size to change or the items within?
Nope I actually fixed it :)
ah good
yep, it sounds like that would do the trick
@queen mist how do you want to restart the app? If you just want to remove everything you can use .destroy() on the canvas and then re draw the canvas with the same arguments you passed in the first time.
This is where classes come in handy for me, i just delete the current instance of the class and create a new one, that acts like a restart function.
Or you could just use canvas.delete('all') depending on what you want.
database.tag_configure("light", background = "white")
database.tag_configure("dark", background = "light blue")
Noloops = 0
for content in Column_Labels:
if Noloops%2 == 1:
database.insert(parent='', index = 'end', iid = Noloops, text = "", values = ("lol", "2", "xd"), tags = ("light",))
if Noloops%2 == 0:
database.insert(parent='', index = 'end', iid = Noloops, text = "", values = ("lol", "2", "xd"), tags = ("dark",))
Noloops += 1
```yo why does this function not work anymore?
Sorry DaRoque, I'm a tk newb and can't help you. I'm guessing you trying to alternate the highlighting of columns. At the very least it looks like your loop is set up correctly, so beyond that IDK.
Proving my noobishness, my question is, with the following code:
text.tag_add("start", "1.8", "1.13")
text.tag_config("start", background="black", foreground="green")
is text.tag_add making "start" a variable that is holding the location of 1.8/1.13? and in the next line, is config using that range to apply the formatting? I assume that is happening but the documentation is kinda vague so I wanted to be sure. Thanks.
ive never used classes!! before, they life functions??
look at this example, to demonstrate how i like to use classes, it even works for the restart thing you want:
from tkinter import *
from time import sleep
class Window(Tk):
def __init__(self):
Tk.__init__(self)
self.draw_widgets()
def draw_widgets(self):
self.restart_but = Button(self, text = 'restart', command=self.restart_app)
self.restart_but.pack(side='top')
def restart_app(self):
self.destroy() # destroys the main window.
sleep(1)
new = Window() ; new.mainloop()
if __name__ == '__main__':
root = Window() ; root.mainloop()
it restarts the window after a time delay of 1 second. @queen mist
classes are the best, majorly because they are properly structured, and it's the best practice to use classes.
ima start using them, they look neat ^
is curses in python system independent?
What is wrong
Well there is an existing function that makes a treeview have striped details so that it would be much easier to read at, but that function does not work anymore for some reason ;-;
Are there any other working functions that does the same thing that works?
Its okay lol at least u replied
Obviously there is no thing default. I don't see what is wrong. What is wrong, does it not show? Does it give an error? Does it freeze? @digital rose
Not a variable, a tag. But yes it works almost the same way
class TopLevelWindow(QtWidgets.QMainWindow):
def __init__(self,Abs):
super().__init__()
self.canvas = MplWidget(Abs)
self.setCentralWidget(self.canvas)
class MplWidget(FigureCanvasQTAgg):
def __init__(self,Abs, parent=None):
f = Figure()
super(MplWidget, self).__init__(f)
self.setParent(parent)
#plot stuff here
def onclick(self,event):
if event.button == 1:
#update plot with stuff
So this is the base of my code. Curious how I would automatically update the figure once conditions are met. Currently itll only update if I move the window around
this is what i get with
def cmd():
os.system('cmd.exe')
cmd_button = Button(homee, text="💻CMD", font=("impact", 20), bg="gray33", borderwidth=1, fg="orange", command=cmd)
cmd_button.place(x=350, y=150)
pls ping me
What is wrong?
The proggram is crashing anf the cmd is not opening
Hmmmm my assumption is it takes some time to execute that command and hence the freeze.
I also think, you are looking for os.system('start cmd.exe') @digital rose
ohhh worked ty
tysm!
subprocess.popen() is better
It is threaded or something right. If yes, then it is better @digital rose
Can we merge electronjs with python or are there any other thing like that in python
EEL
Python EEL combines HTML, CSS and Python
!pypi eel
oh coool thx
@tawdry mulch Sorry for the late reply, but thank you for your help. Trying to wrap my brain around tk with some tutorials.
generate_new = tk.Button(root, text = 'Generate new bits', command =gen_bits_function)
def sort_bits(bits_sort):
bits_sorted = bits.sorter(bits_sort)
sorted_bits = tk.Label(root, text = str(bits_sorted)).pack()
def gen_bits_function():
global gen_bits
gen_bits = bits.generate()
generated_bits.forget
generated_bits = tk.Label(root, text = 'Generated bits: ' + str(gen_bits)).pack()
Why does it says that my function does not exist?
File "C:\Users\A\Desktop\list\main.py", line 17, in <module>
generate_new = tk.Button(root, text = 'Generate new bits', command =gen_bits_function)
NameError: name 'gen_bits_function' is not defined
```
Because python runs code from top to bottom and when it reaches your button, AT THE POINT, function is not defined. It is only defined after the button definition. So either move the button down or the function up.
Which though 😛
I am pretty sure I saw a video combining electron js and python, just a min
Learn to make a modern looking, cross platform desktop apps using ElectronJS with Python.
Use electronJS as a front end for your Python apps.
NodeJS: https://nodejs.org/en/
ElectronJS: https://electronjs.org
python-shell: https://www.npmjs.com/package/python-shell
Code: https://github.com/SouravJohar/python-app-with-electron-gui
for Electron like in python, there is Eel https://github.com/ChrisKnott/Eel
Eel is pretty cool, ngl
Which what? lol
Which help where you referring to. I mean nvm, its fine, as long as you found it helpful 😄
lol, my bad. My questions about
text.tag_add("start", "1.8", "1.13")```
and if start was a variable or not. I guess I could have said pseudo-variable for TK use.
Oh okay, well yes. Even canvas objects use these tags and is much better than creating a variable and storing it inside, rather using tags
But i got another botton on top of a function and it returns no errors
Did you try the solution I said? Post that code then, let me take a look
What is the best widget for showing items fetched from a database (like a table) with qt quick? Any idea?
Most apps that display tables from a database use a tableview
anyone have any thoughts on why the button_press_event handling will connect/work but my key_press_event wont register?
Took out all the functionality, but onclick is definitely connected and working in the actual code
class MplWidget(FigureCanvasQTAgg):
def __init__(self,Abs, parent=None):
f = Figure()
self.fig = f
self.wc = None #initialize overall parameter
super(MplWidget, self).__init__(f)
self.setParent(parent)
#do some plot stuff
# Set up connectivity
self.cid1 = self.mpl_connect("button_press_event", self.onclick)
self.cid2 = self.mpl_connect("key_press_event", self.onpress)
def onpress(self,event):
#do keyboard pressy stuff
def onclick(self, event):
#do clicky stuff
class TopLevelWindow(QtWidgets.QMainWindow):
def __init__(self,Abs):
super().__init__()
self.canvas = MplWidget(Abs)
self.setCentralWidget(self.canvas)
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
w = TopLevelWindow(Abs)
w.resize(1300,850)
w.show()
sys.exit(app.exec_())
well if anyone else happens to be curious
self.setParent(parent)
self.fig.canvas.setFocusPolicy( QtCore.Qt.ClickFocus )
self.fig.canvas.setFocus()
two lines after setParent are needed to activate the keyboard events
I'm working in PyQt5 and trying to have it so that when a button is click the animation playing on the label is changed. However, it doesn't work:
Main_Window.screen.sprite = Animations.confident
print ("Hello.")
def screen(self):
sprite = Animations.normal
gif_background = QLabel(self)
gif_background.setGeometry(40, 60, 107, 100)
gif_background.setStyleSheet("background-image : url(C:/Users/nomar/Dropbox/Blueprints/Background.jpg);")
gif_background.movie = QMovie(sprite)
gif_background.setMovie(gif_background.movie)
gif_background.movie.start()
def textbox(self):
text = QLabel ("Welcome to the Dice Game!", self)
text.setGeometry(165, 30, 300, 100)
text.setStyleSheet("color: white")
text.setFont(QFont('Advanced Pixel-7', 16))
class Animations:
normal = "C:/Users/nomar/Dropbox/Blueprints/Trucy_Normal1.gif"
confident = "C:/Users/nomar/Dropbox/Blueprints/Trucy_Confident_Speak1.gif"```
@coarse mirage use stylesheets property selector
And u need to declare the image in the resource pack of the app
It's kind of a way to test of how to change the image of a label via a different function or even class. Since I plan to have the label show different "reactions" depending on a game the user plays.
you have sprite assigned to Animations.normal in screen() and it never gets reassigned.
How do I get it to reassign? I'm trying to have def button_click(self): Main_Window.screen.sprite = Animations.confident do so.
are you trying to toggle the image every time the button is pushed?
I'm trying to get it to change the image.
The problem with that is the GIF that you use in QMovie is always sprite. That assignment you have at the top of button_click doesn't affect the movie at all
Basically I'm going to be making a dice game and depending if the user wins or lose that will change how the sprite reacts.
Assigning it via button press is more of a "test"
Is there a way I can code it so that it can effect the sprite?
@worthy ridge already gave you the good advice on how to handle it, I think you should take their advice.
Use an if else statement based on whether they win or lose
if won:
sprite = 'gif1'
else:
sprite = 'gif2'
movie = QMovie(sprite)
....
I still think you should use the properties that were suggested earlier, or QStateMachine
I'll look into thanks.
# Since there are 12 months in a year, these are the final days for each month in order
days = (31, 28, 31, 30, 31, 31, 30, 31, 30, 31, 30, 31)
def main():
__name__
menu()
stepTracker()
def menu():
print('Here is your workout information for the year: ')
def stepTracker():
stepCounter = open('steps.txt', 'r')
monthCount = 0
for num in range(0, 12):
totalSteps = 0
count = 0
average = 0
for count in range(0, days[monthCount]):
steps = int(stepCounter.readline())
totalSteps = totalSteps + steps
average = totalSteps / days[monthCount]
print('The average steps taken for the month of ' + month[monthCount] + ' is:' + format(average, ',.1f') + 'steps.')
monthCount = monthCount + 1
main()```
how do I implement a GUI in my code?
Have you tried anything? tkinter?
yeah ive used tkinter, am kind of unfamiliar with it
Simple to use it
What is step.txt.
@coarse mirage set lable properts in pythons and the use that property to change the css
hi how do i open a image and open it in a canvas using tkinter
hi how do i open a image and open it in a canvas using tkinter
please don't spam, please say what you have tried, please actually search such a simple thing before asking
@civic lava i would suggest using PhotoImage() to open image files.
from tkinter import *
root = Tk()
image=PhotoImage(file='/path/to/image.png')
c = Canvas(root) ; c.pack(side='top', expand=True, fill='both')
c.create_image(100, 100, image=image)
root.mainloop()
just replace /path/to/image.png with the actual path of the image.
Keep in mind though, tk.PhotoImage can not open 'jpg' images @civic lava
If someone created a python & Electron app then would the final version of the app need to have python integrated in it?
I don't see why you would need to include python. Assuming you're using python for something like a backend server with cherry py or flask.
though since electron makes it easy to bundle cross-platform apps I don't see a reason not to include python
I have made an calculator in python using tkinter but
Title bar of my Calculator
https://i.stack.imgur.com/t8Twl.png
Title bar of Windows calculator
https://i.stack.imgur.com/kUUR1.png
I want to make it look like the windows one
class mainWindow(QtWidgets.QTabWidget):
def __init__(self,Abs, parent=None):
self.Abs = Abs
super(mainWindow,self).__init__(parent)
self.tab1 = QtWidgets.QWidget()
self.addTab(self.tab1,'First Ions')
self.fig = Figure()
self.canvas = FigureCanvasQTAgg(self.fig)
layout = QtWidgets.QVBoxLayout()
layout.addWidget(self.canvas)
self.tab1.setLayout(layout)
if len(self.Abs.ions) > 6:
self.fig2 = Figure()
self.tab2 = QtWidgets.QWidget()
self.addTab(self.tab2,'Additional Ions')
self.canvas2 = FigureCanvasQTAgg(self.fig2)
layout2 = QtWidgets.QVBoxLayout()
layout2.addWidget(self.canvas2)
self.tab2.setLayout(layout2)
#do app stuff
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
main = mainWindow(Abs)
main.resize(1300,850)
main.show()
sys.exit(app.exec_())
So I was trying to change the style of my lil app. And noticed changing the style did absolutely nothing. Is this due to not putting anything in a frame, so its essentially just opening up tabbed pyplot windows and theres no Qt frame for me to edit the style?
- putting this in a frame, will it change any of the functionality from the event handling with mpl?
- without putting it in any container, do I have any sort of options to change the window style or add a save button or anything else?
looking a bit boring currently
Also is there a way to change the tab's appearance? Couldn't find any documentation or questions related to modifying that
@hybrid spindle dm me i have a style sheet
hey all, i'm trying to make my first GUI using Tkinter for my todo list
is anyone here an expert and able to provide me with some help?
this stressing me out lol
What do you need help with?
i'm trying to make my todo list into a GUI
with a text entry where the user can input their to-do items and an 'add item' button that puts the text entry onto the item list
You can use a Listbox for inserting items into.
im trying to make a listbox now
wait what have i missed, not defined tkinter
but normally this works
import tkinter as tk
win = tk.Tk()
listbox_tasks = tkinter.Listbox(win, height=3, width=50)
listbox_tasks.pack()
win.mainloop()
I dont get you.
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.
@digital rose
import tkinter as tk
win = tk.Tk()
def add_task():
task = entry_task.get()
listbox_tasks.insert(tk.END, task)
listbox_tasks = tk.Listbox(win, height=3, width=50)
listbox_tasks.pack()
entry_task = tk.Entry(win, width=50)
entry_task.pack()
button_add_task = tk.Button(win, text="Add Task", width=48, command=add_task)
button_add_task.pack()
win.mainloop()
i have this so far
but i'm getting this error - AttributeError: type object 'Listbox' has no attribute 'Entry'
nvm fixed it
how would i go about making a listbox widget that shows all items in my list?
You can run a for loop that goes through your list and appends items in the listbox.
A simple example based on your code without using any loops(just using *):
import tkinter as tk
win = tk.Tk()
lst = [1,2,3,4,5]
listbox_tasks = tk.Listbox(win, height=3, width=50)
listbox_tasks.pack()
listbox_tasks.insert('end',*lst)
win.mainloop()
Also keep in mind, these height and width are not pixels.
QPushButton{border-image: url(C:/Users/Kevin/AppData/Roaming/vlc/art/artistalbum/James Arthur & Anne-Marie/The Greatest Showman_ Reimagined/art.jpg); background-color: transparent;}
somehow this gave me an error
Could not parse stylesheet of object QPushButton(0x28893a31500)
but i couldn't see anything wrong with the qss script
its because of the &
ah, hold on.
you need to pass the path like a string in python using the double quote
now it works
i just get used to pass in the path without the double quote which usually works
Yeah there are some characters that require it. I'm not sure if you could use some sort of html escape without the quotes but its probably just easier to make sure there are quotes when you have something other than underscores/hyphens and slashes
yeah makes sense
Apparently all you need is a backslash before if you're doing it without quotes. \&
I'm still going to use the double quote because i want to pass a variable to the url();, not a constant
Are you changing the entire stylesheet of the button or something?
Oh, gotcah.. I just thought I somehow overlooked a way to use variables within a stylesheet.
haha no
and another cool thing i did is change the dropshadow color according to the album art
Is that with the qgaphics effect applied to the button?
yes
if you decide to add other graphics effects you should keep an eye on your CPU usage. I think there is some sort of bug in Qt that causes them not to be discarded properly or something. I had an app that I used a couple of them in and after having it open for awhile the python process would slowly creep up to 100%
it stopped when I removed the effects
but I do like how the effect matches the art
huh, interesting. though fortunately i hadn't encountered that problem
the cpu usage is averaging on 2 - 4% usually and 32% max
it only jumps up when resizing
thats actually pretty good. Is that when playing a track?
yes!
nice
I think instead of using QML and linking with python it is rather more easier to use PyQt right. Python as a backend for QML seems just time consuming idea.
Hmmmm, I see
@plush streamu need to compile it into a resource back to use images in stylesheet and the path is not CSS compatible no spaces
tkinter: hi! what event triggers when the cursor position changes in a textbox?
wait so, QSS is basically CSS?
cursor position changes, either when you insert a character in the text box, or you navigate through the text with the arrow keys. take a look at this example, which makes use of the "<KeyRelease>" event to check for cursor position whenever you let go of any key on the keyboard.
from tkinter import *
def check_cursor(event):
cursor_pos = event.widget.index('insert') # returns position of the cursor in this format: 'line.column'
print(cursor_pos)
root=Tk()
t=Text(root, font=('DejaVu Sans Mono', 15, 'normal'))
t.pack(side='top', fill='both', expand=True)
t.bind('<KeyRelease>', check_cursor)
t.focus_set() # adds focus to the text widget.
root.mainloop()
another thing, that even mouse actions can trigger cursor position changes, for example, when you move the cursor to a different position in the text you've entered.
a really decent hack would be to use the built - in event '<<CursorChange>>' to check for any cursor position changes, as well, you might call that a lazy solution.
is there anyway to make a radio button deselectable in tkinter?
yes, you can bind the radio button to a command that deselects it on clicking it, so that it can never be activated.
another way is to set its state to 'disabled', which greys the radio button out.
I need some help with tkinter
Please?
Help
I just need the piece of code that allows you to save and load Image files
Use filedialog to load
Hwo do i specify the filetype
The thing is, i know how to add a save button, and save a file, but i don't know how to load, or specify the file type...
Use the filetype option
filedialog.askopenfilename(filetype=[('jpeg','*.jpeg')])
What?
TY alot!!!
Hmmhmm xd
You want to deselect or disable it? Deselect it with deselect() method of radiobuttons
TY ALOT
In some way yes! But unfortunately it doesn't fully support all the features that are currently in CSS. So yeah it's very limited.
Ah I see
How do we define the IMage file type?
What is IMage
the best thing i felt abt css is the transition and how ez it is to apply it.
hi so i have this line
self.button0 = Button()
but some reason when i later print self.button0, its a NoneType
Because your code is like self.button0 = Button().pack(). @arctic frigate
Here's how to format Python code on Discord:
```py
print('Hello world!')
```
These are backticks, not quotes. Check this out if you can't find the backtick key.
yeah one sec
https://github.com/UGLYclown999/Apollo
@plush stream
U can get most of the widgets covered
I use resources pack and the theme is like generated using a pallete so the sheets have placeholders
Thanks!
Hey @arctic frigate!
Uh-oh! It looks like your message got zapped by our spam filter. We currently don't allow .txt attachments, so here are some tips to help you travel safely:
• If you attempted to send a message longer than 2000 characters, try shortening your message to fit within the character limit or use a pasting service (see below)
• If you tried to show someone your code, you can use codeblocks
(run !code-blocks in #bot-commands for more information) or use a pasting service like:
@tawdry mulch
https://paste.pythondiscord.com/kefagoqogi.rb
heres the code
if anyone else could help, that would be great
did you call the method menuSet
its called in the constructor
Ok i see its called before self.button0 = None so it then becomes None
oh i see that now
how do i disable an entry i ntkinter? rn im doing ```py
month_entry = Entry(top).grid(row = 4, column = 2)
if before_or_since.get() == 3:
month_entry.config(state = 'disabled')
else:
month_entry.config(state = 'normal')
i get the error ```py
month_entry.config(state = NORMAL)
AttributeError: 'NoneType' object has no attribute 'config'
i tried doing month_entry.config(state = 'DISABLED') and month_entry.config(state = DISABLED)
i also tried month_entry.configure(state = 'disabled')
do the grid call separately from creating the button .grid() returns None
month_entry = Entry(top)
month_entry.grid(row = 4, column = 2)
it launchs without an error now but it still wont disable
basicly im trying to make it so when a radio button is selected the entry becomes disabled
from tkinter import *
top = Tk()
day = StringVar()
month = StringVar()
year = StringVar()
before_or_since = IntVar()
top.geometry('600x600')
title = Label(top, text = 'Email Sorter', font = ("Arial", 20, "bold"), relief = 'solid', padx = 10, pady = 5)
label2 = Label(top, text = 'Select Options', font = ("Arial", 16, "bold"))
before_label = Label(top, text = 'Select Either Before or Since', font = ("Arial", 12), justify = 'center', pady=30).grid(row=3, column=1)
before_rb = Radiobutton(top, text='Before', value = 1, variable = before_or_since).grid(row=3,column=2)
since_rb = Radiobutton(top, text='Since', value = 2, variable = before_or_since, justify = 'left').grid(row=3,column=3)
none_rb = Radiobutton(top, text='None', value = 3, variable = before_or_since, padx = 60).grid(row=3,column=4)
since_label = Label(top, text = 'Enter a Date', font = ("Arial", 12), justify = 'center').grid(row=4, column=1)
month_entry = Entry(top)
month_entry.grid(row = 4, column = 2)
quit_button = Button(top, text = "QUIT", font = ("Arial", 12, "bold"), fg = "black", relief = "groove", command = exit)
title.grid(row = 1, column = 2, pady = 20)
label2.grid(row = 2, column = 2, pady = 20)
if before_or_since.get() == 3:
month_entry.config(state = 'disabled')
else:
month_entry.config(state = 'normal')
top.mainloop()
Do you know about event driven programming?
whats that?
helo can anyone pls help me with cx_freeze and pyqt5
Keep in mind to put the if inside of some function
oh
oh awesome it worked!
tysm
You have called the disable code before the gui event loop is running, you need to react to events in the GUI like the radio button click happening and then update the GUI in the event handler.
the gui event loop is tk.mainloop()?
i am trying to convert my qt5 project to exe using cx_freeze but its converts successfully and even runs it but i duno why whenever i click on any widget it crashes, now i noticed it doesn;t happen when i remove the base from the cx_freeze setup file```python
target=Executable(
script="main.pyw",
base="Win32GUI",
icon="icon.ico"
)
Yes
#user-interfaces message anyone pls
it tkaes a while but someone will respond probably
ah ok ty
from tkinter import *
top = Tk()
day = StringVar()
month = StringVar()
year = StringVar()
before_or_since = IntVar()
def an_event_handler():
if before_or_since.get() == 3:
month_entry.config(state = 'disabled')
else:
month_entry.config(state = 'normal')
top.geometry('600x600')
title = Label(top, text = 'Email Sorter', font = ("Arial", 20, "bold"), relief = 'solid', padx = 10, pady = 5)
label2 = Label(top, text = 'Select Options', font = ("Arial", 16, "bold"))
before_label = Label(top, text = 'Select Either Before or Since', font = ("Arial", 12), justify = 'center', pady=30).grid(row=3, column=1)
before_rb = Radiobutton(top, text='Before', value = 1, variable = before_or_since, command=an_event_handler)
before_rb.grid(row=3,column=2)
since_rb = Radiobutton(top, text='Since', value = 2, variable = before_or_since, justify = 'left', command=an_event_handler)
since_rb.grid(row=3,column=3)
none_rb = Radiobutton(top, text='None', value = 3, variable = before_or_since, padx = 60, command=an_event_handler)
none_rb.grid(row=3,column=4)
since_label = Label(top, text = 'Enter a Date', font = ("Arial", 12), justify = 'center').grid(row=4, column=1)
month_entry = Entry(top)
month_entry.grid(row = 4, column = 2)
quit_button = Button(top, text = "QUIT", font = ("Arial", 12, "bold"), fg = "black", relief = "groove", command = exit)
title.grid(row = 1, column = 2, pady = 20)
label2.grid(row = 2, column = 2, pady = 20)
top.mainloop()
ty i figured it out
@digital rose try logging the app
ah ok
Because sometimes qt supresses errors
oh alright ima use the logging module then and reconvert to exe
Nope like it is used to make exes and freeze
ah aight
also do u know how to fix this, ;-; i only added those modules to include but cx_freeze include every package on my pc welp
I dk much about cx
aoh, so should i use nautika to convert to exe?
is it gud
@worthy ridge i logged the app behavior and it output an error, but duno wut this means cuz i didn;t get this whne running the py file
I nwex code
when i run the .py file it works fine
nwex?
Need
i wrote an api to download animes and implemented into the gui, the self.api is the api
ah ok
mmmmmm @worthy ridge r there any other packages to convert py to exe
no pyinstaller
:-:
Nuitka
aoh aight ima gib it a try
can u tell me how to install nuitka
pip install Nuitka?
ok it works
umm ok install done how do i use it
@worthy ridge can u tell me pls how do i use nuitka?
i'm getting this error
ima search on yt
but ty for the help
.topic
Suggest more topics here!
.topic
Suggest more topics here!
on simple words, yes
GUI
GUI
GUI
Hahaha lol nothing IMPRESSIVE, but https://github.com/nihaalnz/ToDoApp and https://github.com/nihaalnz/MPlayer are worth a look I guess.
But CLI it not bad
not bad, better performance too
Yes
currently i make a tor based decentralized heberger
Have no idea what it is, but sounds cool
xD
Thks
The project is: the user install a script in his computer, in a GUI he enter his informations (nbre of prossesors, nbre of hearts, nbre of RAM,ect)
After that, we test his bandwidth et we deduct a price from its configuration
After, we will have to be able to make the computers talk to each other without going through a server
Sometimes our brain ignites
.topic
Suggest more topics here!
Damn, I see
Ummmm 'cmd' 😛
this event is actually what I'm looking for, but when testing, it didn't activate whatsoever
Hmmmm I could not get it too @polar wave
Yes, thats why the KeyRelease event is better.
i did use <KeyRelease> but i used <KeyPress> at the same time because the thing I'm making needs constant updates
I dont get you. For constant updates, the '<Key>' event should be better, that is triggered as soon as you press a key, but it rather gives the previous position of where the cursor was.
yea... that was a problem for me... but using <KeyRelease> and <KeyPress> worked and i didn't get any issues.
So when starting to type your cursor would be at '0.0', and pressing a key would print '0.0', but after inserting a character, it becomes '0.1', so it is not correct.
When using Key
yea...
The problem is, python is too slow to grab instant keyboard events, so another approach you could try maybe is to tell tkinter to look for cursor changes every 50 milliseconds, though that is kind of rough.
oh ok.
i have another question though.
How do I make the textbox fill all the unused space? i'm using the grid system btw
What do you mean by fill all unused spaces?
like it filling the whole column and stretching to the end of the window.... but configuring the columns and rows doesnt seem to work
This confuses me further. Anyhow, you need to use the expand and fill attribute in pack, that solves your purpose i think:
textbox.pack(side='right', fill='both', expand=1)
can i use pack with grid though?
I dont think you can.
Im pretty sure tkinter would throw a TclError saying that you cannot use pack when widgets are rendered using grid.
it still doesn't stretch....
sorry, just found the problem....
in any case, you can interchange .pack() and .place().
so it could be better to use both of them throughout the app.
I never found much of a reason to use place and tbh pack feels quite uncontrollable to me.
Makin cells resize with grid is possible, although more annoying than with place. All cells start out with a default row/column weight of 0, which means they will grow as large as their contained widgets demand and no more. You need to set the weight to something larger than 0 by calling w.grid_columnconfigure(0, weight=1) and w.grid_rowconfigure(0, weight=1), which will cause widget w's grid column 0 and row 0 to expand whenever w should resize; so to apply that to the textbox, call these methods of the text's parent widget and target the row/col that contains the text widget. You'll need to grid the text with sticky="nsew" as well to make it stick to the edges of its container cell and grow with it. [ @polar wave ]
anyone have any idea how to style the QTableWidget/QTableView in qss? couldn't find any details from the doc on how to do it.
What do you want to do?
edit the headers
This is from one of my old projects maybe it will help
QHeaderView {
font-family: "Open Sans Light";
font-size: 14px;
}
QHeaderView::section {
height:39px;
font-size: 14px;
padding-left: 5px;
padding-bottom: 0;
padding-top: 0;
border: 1px none #ccc;
border-bottom: 1px solid rgb(40,43,45);
border-left: 1px solid rgb(53, 57, 59);
background:rgb(84,89,99);
color:#fff;
}
QHeaderView::section:first:horizontal {
border-left: none;
border-right: none;
}
QHeaderView::section:last:horizontal {
border-right: none;
}
QHeaderView::section:first:horizontal {
border-left: none;
border-right: none;
}
just trying to match the style
thanks!
ah yeah I think you should be able to get that changed.
let me know if you find out a way to set/resize the width of the columns when the window resizes in an intelligent way. I gave up on it and just used stretch on the last column
is this what you mean?
Yeah I think thats pretty much it
def resizeEvent(self, event):
self.playtable.setColumnWidth(0, int(self.playtable.width() / 4))
self.playtable.setColumnWidth(1, int(self.playtable.width() / 4))
self.playtable.setColumnWidth(2, int(self.playtable.width() / 4))
self.playtable.setColumnWidth(3, int(self.playtable.width() / 4))
so it's taking the QTableWidget's width and then divide it with the number of column you have
Yeah I think I tried something like that, my problem was if I changed the width on one of the cols manually It was hard to get that one to stay the sameish percentage without a bunch conditionals and making the resize kind of laggy/jumpy when I changed the size of the window after
and without those conditionals it was infuriating when I resized
I've tried many different way to do it but none of them works/broken. this is the closest i can get to what i want
Yeah I think I tried a couple of different things but it was never quite right
I need to sit down one day when and figure it out... I bet if i read the docs more closely it would be easy to figure out
we all know reading the docs is boring 🙂
but sometimes it saves you a hell lot of time
It would save so much more time if PySide/PyQt generated doc strings
Tkinter: How do you make the window like what you get when you have the tear-off set as True in a window? I'm talking about this but I don't know what it's called.
tear off menu? iirc
yes, but it's a window that you can customise.
the other place i can see it is in paint.net...
helo can anyone help me with nuitka, how can i include my modules to the package
during conversion
sed
I think you're talking about a tool window, that only has an exit button, and can be used as a sub-window.
You can make your own by saying:
foo=Tk()
foo.wm_attributes('-toolwindow',True)
And keep in mind, this removes the window from the taskbar.
This attribute only works on Windows.
oh, thanks! im going to try it later. does it work on TopLevel too?
Yes.
nice!
How can I keep pyqt5 window on top even if I focus to another window
set a window flag with Qt.WindowStaysOnTopHint
you can post your problem here.
from tkinter import *
root = Tk()
root.geometry("500x220+500+200")
root.title("Reverse number Game")
root.configure(background='light green')
heading = Label(root, text="Welcome to mind Game ", fg='black', font='arial 15 bold').grid(row=0, column=3)
def secondPanel():
FirstMove = Label(root, text="First Move", font='arial 10 italic').grid(row=1, column=2)
Player1 = Label(root, text="Player 1 :", fg='black', bg='red').grid(row=1, column=2, pady=20, padx=5)
Player2 = Label(root, text="Player 2 :", fg='black', bg='red').grid(row=2, column=2, pady=10, padx=5)
Player1Name = StringVar
Player2Name = StringVar
p1Entry = Entry(root, textvariable=Player1Name).grid(row=1, column=3, padx=50)
p2Entry = Entry(root, textvariable=Player2Name).grid(row=2, column=3, padx=50)
submit = Button(root, text="Start",command=secondPanel).grid(row=4, column=3)
root.mainloop()
As soon as click on btn, player2 label and p2entry should disapper
How can I do it
!code
Here's how to format Python code on Discord:
```py
print('Hello world!')
```
These are backticks, not quotes. Check this out if you can't find the backtick key.
What happed? I don't understand
ok, anyways, to make a widget invisible you can say:
Player2.pack_forget()
# and
p2Entry.pack_forget()
but your widget handling is quite poor, once you create the widget and use .grid() in the same line, the widget becomes a NoneType object, so put the grid in a separate line.
Ight works
further more, you can bind that to a button, you can use it as a command, and associate the command to the button:
def make_invis():
Player2.pack_forget()
p2Entry.pack_forget()
submit = Button( .. .. ., command= make_invis)
. .. .. .
do not change the rest of the code
@lean oak
ayo check this out, i found a qss editor that apply your stylesheet in realtime. it even has autocomplete suggestions. might be handy
oh and it allows you to use variables within qss
It's saying NoneType object has no attribute pack_forget
you are not reading my messages completely, i told you to put the grid statement in a separate line, otherwise the widget becomes a NoneType. @lean oak
^
make sure you save your file frequently if you're going to use that. Its not very stable
or at least it wasn't about a year ago
A very big mistake I see people doing is not instantiating properly. Where did you get this code from?
It should be Player1Name = StringVar() and so on...
its fine, its not a thing to be bothered about when some one is a newbie, as they said themselves. its fine as long as their code works.
How would a code "work" when you don't instantiate a class properly xp
nope. it crashes within 7 minute of use 😦
you dont need string vars for everything, theres always config, and on top of it, it is always good practice to include variables and handle them properly.
I did not say to use StringVar(), if your using it, use it properly atleast
At any point use set() or get(). Its pointless, it will give error
i do know he hasnt said StringVar(), and instead has said StringVar.
its from a general perspective.
I never use StringVar()
unless I want to use trace().
Or when using a grouped widget
it doesn't handle invalid syntax very well, does it?
a newbie should be using best practices to learn, else they will always remain newbie. No offence 😛
i see. guess it applies to everyone round here.
I also used StringVar, but somebody in here said it's StringVar
Thats ok
you need to add parentheses there, like this:
StringVar()
or else the class wont be instantiated.
I want help, plz viseur I have already placed grid in new line, but same error
what error are you getting?
Why are you using a StringVar(), to get the values right, just try Player1Name.get()
not call, but you can dm me for sure. feel free to do that.
apparently it crashed because the app can't access certain files due to insufficient permission (i looked through the traceback). so launching it as admin fixed the problem.
in the windows temp dir or something?
a general question, how is syntax highlighting handled in real time in IDEs? because seemingly highlighting text on key presses makes it a bit slower.
at least in python.
I think there were issues if you used a non hex color, like rgb(255,0,0).
Yeah, I cant remember every crash but I do remember thinking it would be pretty cool if it wasn't so unstable.
there is however a more stable alternative that i found
and dont even think about using a palette color as a variable!
what do you mean?
Are IDEs coded in python 🤔?
i thought IDLE was 😛
IDLE is made in tkinter, AFAIK
i thought tkinter was in PYTHON.
You mentioned IDE, not IDLE
like palette(button), ya know?
oh
its fine if you dont know the answer to my question. IDLE is an IDE, coded in python, also a general purpose text editor.
i like idle for quick script
and when i say IDE it can be any, out of the ones created in the world.
The IDE I use is VS Code maybe you should search out what all IDE exists out there
does that answer the question?
^
IDLE is one of the many, not the only one. Pretty sure VS Code is not done in Python
my question was about "handling syntax highlighting in real time" not - "tell me about IDEs" @tawdry mulch .
There are several IDEs that are made with Python
https://www.spyder-ide.org/ is probably the best example
Website for Spyder, the Scientific Python Development Environment
What makes you think about the keypresses? are slow
i see, spyder is one of nicest looking editors.
Kinda reminds me, there is an library for syntax highlighting with python
QScintilla
has anyone tried pyside6 yet
yes, missing a lot of basic stuff
Has a version for python? @eager beacon
like QImage formats
yep
im looking for QtWinExtras but i hadn't find it
Damn can be usefull
yeah, 6.2 is the goal for most of the missing stuff I think
there is a blog post somewhere that has a roadmap
Shouldnt they have done it together at first version itself? @eager beacon _
Cascades?
Image I meant
Well he meant, that Menu() has a tearoff=True option, to replicate that effect on a window @chrome sail
Well depends
Upper or Lower-case?
Well, try both :p
Lower I assume
share that line of code @chrome sail
def saveFile():
ProPixelSave = filedialog.asksaveasfile(filetype=[('jpg','*.jpg')])
Tis wud open all jpg files
filetype=[('jpg','*.jpg'),('png','*.png')] Try this now
def openFile():
ProPixelOpen = filedialog.askopenfilename(filetype=[('jpg','*.jpg')])
Thnx imma try!
The first part of the tuple is what you see down there, the second part of the the tuple is the file extension to choose from
In IDLE i think it uses pygments
what are you guys tryna do
Who!! @plush stream
No. It applies tags using some constant patterns defined in some file, and uses re to do that.
Oh I see
Did not know this: https://docs.python.org/3/library/idle.html#developing-tkinter-applications
How do I reduce the amount of space between each column in tkinter? I have to fit 7 widgets in one row
I tried using sticky and padx
month_entry = Entry(top, width = 2)
month_entry.grid(row = 4, column = 3)
month_label = Label(top, text = 'Month', font = ("Arial", 10)).grid(row=4, column=2)
day_entry = Entry(top, width = 2)
day_entry.grid(row = 4, column = 5)
day_label = Label(top, text = 'Day', font = ("Arial", 10)).grid(row=4, column=4)
year_entry = Entry(top, width = 4)
year_entry.grid(row = 4, column = 7)
year_label = Label(top, text = 'Day', font = ("Arial", 10)).grid(row=4, column=6)
it runs off the screen
okay ill try that
Wait, I dont understand what you mean, can you include an screenshot
okay
i want them to be next to each other
and the year part runs off the screen
also columnspan did not work
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 think some widget above is using all those extra space @stoic jackal
oh
okay
I cant past full code tho
ill use the paste thing
Kay
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.
Try
title.grid(row = 1, column = 2, pady = 20, columnspan=6)
label2.grid(row = 2, column = 2, pady = 20, columnspan=6)
@stoic jackal
The rest of space is due to padx.
oh awesome its way better now
so the title and label2 were taking up space?
Yep, so make it span across 6 columns
well the column number depends on how many columns you want to include within it
okay
oh so the column was being "stretched'
...to fit the top 2 columns width
PEP8? Interesting ill check it out
Okay I understand tysm
Qt has a gigantic code base and they apparently want to make some changes/reorganize it a bit and they have to do it on the C++ side so its probably really difficult. TBH i don't know how they can make any changes without breaking a lot of other stuff.
Can i use any font that its installed in my PC with tkinter?
I can't see a good reason why you wouldn't be able to
Ok ok
Hmmmm I see
Yes you will be able to
But while sending it to someone else, there will be issue.
lstbox.py line 10
pyglet.font.add_file('fonts/coolvetica compressed rg.ttf') # Add the task font```
Pyglet is a library i need to import?
You need to install it first @versed vessel
Only keeping in mind, this
Issue means, the font wont load and default font will be used. If you check that repo, you can see how I used custom fonts
you can even download the app and try it and see the fonts work
Ok ok
I'll try it
https://github.com/nihaalnz/ToDoApp/blob/03b2835422138b21433495930c239ef76b7268af/lstbox.py#L37
So here i have to put the name of the font im trying to use
lstbox.py line 37
font=('coolvetica compressed rg',30), tag='text') #250,25```
Yea exactly, but make sure the name of the font is the NAME of the font
not the name of the font file
See the Font Name is Roboto
That is what you have to use
Its is working! Thanks a lot!
Just to be sure, make sure to test it later on another system and do let me know 😄
Hmm, i can commit it to github and you can try it if you want
Kay sure, just ping me once your done
Here it is: https://github.com/MrFellox/flimsy-timer
Sorry because i dont have any releases 😅
😄
Nice!
The widgets are in different order because i did some things with the grid before commiting but the font works, thanks a lot!
Yepp
So I have the following within my main app:
def saving(self):
print('clicked')
pdb.set_trace()
button = QPushButton("SAVE",self)
button.setGeometry(550,30,200,30)
#pdb.set_trace()
button.clicked.connect(saving(self))
Unfortunately immediately upon running the program, it prints 'clicked' and calls the debugger. Why doesnt it wait for me to actually click the button to execute the 'saving' function?
Try: button.clicked.connect(saving)
Wait, what. How can you pass in self, it is not a method
Do you really need to pass self to saving?
I did want to access components saved in self.
Then make it a method
keep it in same indentation level as __init__
Then button.clicked.connect(self.saving)
But before all this, do give button.clicked.connect(lambda: saving(self)) a try
beaut
that did it!
Though, try accessing some elements with self and see if it works. It just seems like a very weird way. Rather creating a method seems more conventional (?)
wdym by creating a method
A method of a class.
class Foo:
def __init__(self):
pass
def this_is_a_method(self):
pass
That was probably my issue. I tried it first as a class, but was outside of the main app. Didnt seem to like how I was doing it.
But yeah, I can access everything within self by using lambda
Cool, but seems weird. Indeed I have seen no one do it like that 😛 Cool idea
The more you know! haha
sure, but what are you using it for
The methods?
@hybrid spindle what class have you inherited
yes
Because you can call the methods from anywhere inside and outside the class
eh outside not so easily unless its static
Yeah
app = Foo()
app.this_is_a_method()
Yes
Like that it is usefull 😄
You are calling the function inside the button and hence, calling the function when the button is initialised
A lambda ensures that this does not happen
this is what i was talking about
Hah!
So to conclude @hybrid spindle, When calling or assigning functions, dont use (), that will call the function directly. If the function has no parameters, then just type the func name, else use lambda or partial.
You can pass self in a function depending on what self is
Thats why I asked what class you inherited
Hmmmm, not sure
In tkinter I'm trying to allow users to select serial ports to use and open
I've managed to locate and add all the code to find and add the serial ports into a combobox
but I'm wondering how can I use the user selection in opening the serial port
I'm trying to get it to open the selected serial port... Is their anyway to get this to work
This is the code that I'm using to find and allow users to select com ports: https://srcb.in/hbOnjKxQuw
What is wrong there
I don't know how to open the serial port with the selected com port
the tkinter part doesnt make any issue there, so this isnt really a UI question
It's a combobox and I'm wondering how do I use the selection from the combobox to open a serial port
You get the selection with get(). That is implemented correctly. Opening a port is not tkinter, so...
Google it? @spring ibex
What's a good way to keep code organized when working with GUIs? Using PyQT and my code is an absolute mess. I'm trying to refactor it and put it into a class of some sort, but just not sure how everything would work at that point.
Follow this maybe https://pyserial.readthedocs.io/en/latest/shortintro.html
@spring ibex
Thanks
Do you have an example of GUI code that you would like to refactor?
you want me to send the file, or something like pastebin?
Will it paste here, is it a lot of code ?
like 100 lines, but probably over discord limit of 2k characters
first time messing with GUIs, so some imports might be useless and code might be a mess
but here
I'm not that clued up on PyQt, i will take a look but someone proficient in PyQt might come along and have a look now you code is listed.
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.
Here is the beginnings of changing the code to use a class.
https://paste.pythondiscord.com/rifekodugu.rb
I think i would have to know more about PyQt to tidy it up any further.
P.S. I commented out NetFinder code for it to work for me.
-> None is a type hint my IDE added it, its not necessary you can remove it.
*args and **kwargs allows you to pass multiple arguments and keywords, rather than stating the specific required ones.
whats the point of unspecified arguments?
by doing
class Window(QWidget):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
it passes any arguments or keyword arguments i use to the parent class.
I installed PySide6, not bad move right
Hey guys i have a question. How do you install .Git files on Debian after cloning them
What are .git files? Git repositories aren't "installed". Also, you're in the wrong channel. If you have a question about git, please ask in #tools-and-devops
hi, so i have a while loop at the end of my tkinter file with the update_idletasks() and update() methods in them
i also have so input conditionials from keypresses and it seems that the input is kind of delayed or sometimes does not get registered when pressed
any way to resolve this?
Post the code pls
root.mainloop() is an alternative of update() and update_idletasks() used together inside a infinite loop.
well i needed stuff inside the main loop so i used a while loop with those 2 commands
one sec
while True:
if a1.play == False:
if GPIO.input(switches[0]):
if a1.button == 0:
a1.button = 3
else:
a1.button -= 1
if GPIO.input(switches[3]):
print('f')
if a1.button == 3:
a1.button = 0
else:
a1.button += 1
if a1.button == 0:
a1.button0['bg'] = 'red2'
sleep(.1)
else:
a1.button0.config(bg='white')
sleep(.1)
if a1.button == 1:
a1.button1.config(bg='red2')
sleep(.1)
else:
a1.button1.config(bg='white')
sleep(.1)
if a1.button == 2:
a1.button2.config(bg='red2')
sleep(.1)
else:
a1.button2.config(bg='white')
sleep(.1)
if a1.button == 3:
a1.button3.config(bg='red2')
sleep(.1)
else:
a1.button3.config(bg='white')
sleep(.1)
if GPIO.input(switches[4]):
a1.commands[a1.button]()
a1.update_idletasks()
a1.update()
it works, but i either have to hold the button down or i press it and there's a delay
i know its meh coding design but its for my final project and i kinda through it together bc it's due tomorrow
@tawdry mulch
i also have a portion of the code in pygame and the buttons do not have a delay in the pygame loops
As Chris said Qt 6.2 is going to have all the features so depending on what you are doing, it's probably not a good idea
Pyside6 is currently on Qt 6.1 ig
tkinter: hi! how do i prevent insert() adding a new line when triggered?
In a Text widget?
yes
Can you show some code?
wait for a sec
In any case, by default the text widget is configured to add a newline at the end, so right after you use insert, you can say this:
text.insert(..)
text.delete('end-1c', 'end')
ty! im going to try it.
end-1c means: 1 character before the end of the text widget. So when the text widget inserts a new line, it uses the escape code \n, which is one char.
ok, that's handy. thanks!
No problem. Another thing, when using indices like insert or end, you can use +n chars or -n chars for any positive integer n, to access some number of characters before or after that index.
nice! ty!
hi
Hello
iihiii
time.sleep will stop the mainloop() from updating
I will wait ig 😛
someone just pinged me....
It was me, realized that you got the answer, so its fine.
oh, it's fine. thanks tho 🙂
any idea how i can i make a fixed, frameless window draggable, dont want to resize
in pyqt5
In QML, I had to set some flag and set the min and max height and width to the same dimension. @zenith epoch
It would be same with PyQt5 also, maybe?
you can use the setFixedWidth and setFixedHeight function in pyqt/pyside to set a fixed width to your window
For draggable I used mouse area to the top bar part and then gave it a qt drag handler
and use Qt.WA_FramelessWindowHint for frameless window
Seems like that is QML only feature? DK
oh
oh also talks about qt
i've been facing this issue recently
where i tried to change the color of the QScrollBar
but it's displaying these weird pattern
it's sort of invisible when the color white is applied because it blends
but when it's set to darker color, it became visible
any idea why?
QScrollBar:vertical {
background: rgb(57, 63, 82);
border: 0px solid #666666;
width: 15px;
margin: 0px;
padding-top: 10px;
padding-bottom: 10px;
padding-left: -2px;
padding-right: -2px;
}
if you want a sort of uhh hack, use QSizeGrip
Thnx
np
does anyone know what the supported video formats are available for QVideoWidget
i have searched the docs in QMediaContent, QMediaPlayer, and of course, QVideoWidget and could not find anything
any ideas, maybe I missed something?
Windows: DirectShow
Linux: gstreamer
MAC/iOS: AV Foundation (IIRC all that also QuickTime can play)
NO GUARANTEE FOR CORRECTNESS:
supported video file formats: QuickTime Movie (.mov), MPEG-4 (.mp4, .m4v), MPEG-2, MPEG-1, 3GPP, 3GPP2, AVCHD, AVI, DV;
supported video codecs: MPEG-2, MPEG-4, H.264, H.263 H.261, Apple ProRes, Apple Pixlet, Animation, Cinepak, Component Video, DV, DVC Pro 50, Graphics, Motion JPEG, Photo JPEG, Sorenson Video 2, Sorenson Video 3, H.263, H.261, Apple ProRes, Apple Pixlet, Animation, Cinepak, Component Video, DV, DVC Pro 50, Graphics, Motion JPEG, Photo JPEG, Sorenson Video 2, Sorenson Video 3
supported audio file formats: M4A, m4b, .m4p, MP3, Core Audio (.caf), AIFF, AU, SD2, WAV, SND, AMR
supported audio codecs: AAC, HE-AAC, Apple Lossless,MP3, AMR Narrowband, MS ADPCM, QDesign Music 2, Qualcomm PureVoice (QCELP), IMA 4:1, ALaw 2:1, ULaw 2:1, Integer (24-bit, 32-bit), Floating Point (32-Bit,64-Bit)
@ivory ember
thanks amigo
Read all the replies there, its quite enlightening.
ig i gotta implement checking the supported codecs 😁
Trial and Error, it is
yessir
you can post your query here, for someone to help you.
anyone here play with remi? i am trying to run a few of the example apps and i keep getting an error on any app with a button. anything with a onclick.do throws the error Method 'onclick' has no 'do' member
shit. apparently it works in IDLE but not VSC
What is the code
I have not heard about remi, but maybe I could help
apparently it isnt a remi problem. VSC is being stupid again
as much as i like VSC, it is becoming a PITA
Why would VSC throw an error that doesnt exist
I recommend to show the code, let some1 take a look @autumn badge
class MyApp(App):
def __init__(self, *args):
super(MyApp, self).__init__(*args)
def main(self):
container = gui.VBox(width=120, height=100)
self.lbl = gui.Label('Hello world!')
self.bt = gui.Button('Hello name!')
self.bt2 = gui.Button('Hello name surname!')
# setting the listener for the onclick event of the buttons
self.bt.onclick.do(self.on_button_pressed, "Name")
self.bt2.onclick.do(self.on_button_pressed, "Name", "Surname")
# appending a widget to another
container.append(self.lbl)
container.append(self.bt)
container.append(self.bt2)
# returning the root widget
return container
# listener function
def on_button_pressed(self, widget, name='', surname=''):
self.lbl.set_text('Button pressed!')
widget.set_text('Hello ' + name + ' ' + surname)
# starts the web server
start(MyApp)```
the self.bt.onclick.do(self.on_button_pressed, "Name") throws the error in VSC
why? I have no idea. every once in a while VSC gets buggy and just hates me. I dont change anything and then all of a sudden a certain module (like tkinter) wont work. The next day, it will
@plush stream change add page and sub page sub control
I want to make a simple tax calculator app can someone help me?
Hello, i have a gui with few widgets which are inside a function ,I want to remove(forget)all the widgets when a function is called
don't know if this is the right place to ask but does anyone know if it is possible to interact with closed captions on a google meet(google classroom application)? for example, could you look for a word in the CC and when it pops up, say it's "apple" the code would output something?
possible if Google has an API for it
is there a source where I could check if they do? If not, do you think something could be adapted, maybe a screen recording that could be scanned perhaps?
i dunno. maybe goolge it? #irony
i think google has a site where they list all of the APIs they have
oh alright, I will try that. what do you think about the feasability of the second option? maybe use something similar to the CC tech to look for specific words?
what is your end goal for it? light a light if "apple" is said?
anything really, I would like to make an simple program that can recognize the words in the closed captioning and if a certain words is there, give an output
a primitive version might just to add the word to a list and count how many times it it said
but you could easily expand this
some light reading
...
thanks bud, I will do some more research myself later but this will def hellp. have a nice day !
hmm lemme take a look
Sure, using tkinter?
tkinter?
Great, what is the problem then
looks like this
yes
i wnat it to calculate the Total Due
Show the code, then
ok then, what is total due
Total amount*Tax Percentage
so if you have a 10% tax you will want to set the total to
total = amount + (amount*tax)
Thanks! I seem to have missed that one.
Cool, now show us the code
@plush stream https://github.com/UGLYclown999/Apollo
Works fine on my system
Look up my style
Here's how to format Python code on Discord:
```py
print('Hello world!')
```
These are backticks, not quotes. Check this out if you can't find the backtick key.
ok
lol ikr. it should work but for some reason my windows VSC sucks.
@autumn badge Out of curiousity, why are you not importing the library
expr=""
def calculate_due():
intxt = float(Amount_Entry.get())
txt=float(Tax_Entry.get())
if intxt !="":
Totaldue= intxt*txt
Due_Entry = Label(window, fg = "white", bg = "black", font = "Aleo")
Due_Entry.place(x=150, y=120)
else:
messagebox.showwarning(window,text=" Stop!""Please enter a value")
window=Tk()
window.title("Windows TaxApp")
window.configure(bg="black")
window.geometry("300x200")
Total=StringVar()
Percent=StringVar()
lbl1=Label(window,text="TAX CALCULATOR",fg="white",bg="black",font="bold")
lbl1.place(x=80,y=5)
lbl2= Label(window, text="Total Amount: $",fg="white",bg="black",font="Calibri")
lbl2.place(x=25,y=40)
Amount_Entry= Entry(window,textvariable=Total)
Amount_Entry.place(x=160,y=40,width=50)
lbl3= Label(window,text="Tax Percentage: ",fg="white",bg="black",font="Calibri")
lbl3.place(x=25,y=80)
Tax_Entry= Entry(window,textvariable="Percent")
Tax_Entry.place(x=150,y=80,width=50)
lbl4= Label(window,text="Total Due: ",fg="white",bg="black",font="Calibri")
lbl4.place(x=25,y=120)
# Due_Entry= Label (window)
# Due_Entry.place(x=150,y=120,width=70)
btn1= Button(window,text="COMPUTE",bg="white",fg="black",command= calculate_due)
btn1.place(x=100,y=160)
window.mainloop()
Try this @autumn badge
import remi.gui as gui
from remi import start, App
class MyApp(App):
def __init__(self, *args):
super(MyApp, self).__init__(*args)
def main(self):
container = gui.VBox(width=120, height=100)
self.lbl = gui.Label('Hello world!')
self.bt = gui.Button('Hello name!')
self.bt2 = gui.Button('Hello name surname!')
# setting the listener for the onclick event of the buttons
self.bt.onclick.do(self.on_button_pressed, "Name")
self.bt2.onclick.do(self.on_button_pressed, "Name", "Surname")
# appending a widget to another
container.append(self.lbl)
container.append(self.bt)
container.append(self.bt2)
# returning the root widget
return container
# listener function
def on_button_pressed(self, widget, name='', surname=''):
self.lbl.set_text('Button pressed!')
widget.set_text('Hello ' + name + ' ' + surname)
# starts the web server
start(MyApp)
Code works fine
Do you realize that you have not set the text for the label?
what should i put there?
Due_Entry = Label(window, text=Totaldue, fg = "white", bg = "black", font = "Aleo")
ok
i set the interpreter, it runs but still says that onclick has no do member.
OMG THANKYOU SO MUCH GUYS
YOU GUYS ARE REALLY HELPFUL
You did not import the libraries before
oh......im pretty sure i have
Ok then send the ENTIRE code
the code you sent were missing those, so I added those in and it worked
wait, what di dyou add?
import remi.gui as gui
from remi import start, App
oh shit. i see now. for some reason it didnt grab the entire thing, my bad
So did you have it in your code?
I am in a very early stage to tell that ur python is broken 😛
im sure it is man.
Just a min
actually, i think python is fine
VSC is borked
you got a good way to uninstall it completely? so i can reload it and start over?
i get no errors when trying it with IDLE
so basically, that will always show but it will still run?
Well it should. Don't you have a some sort of terminal?
yea. and i can certainly run it that way.
Press Ctrl + Shift + ` and then try typing 'python filename.py'
@autumn badge https://github.com/UGLYclown999 there is a vscode setup config in my repo look it up in setup guide
So many languages :p
What
@worthy ridge
3 languages and many frameworks
Great!
Blender uses python right
Its great lol
Brilliant, I was too dumb to understand it back then. Mayb 6 years before?
thanks. will dig into it
Nope 2 yrs @tawdry mulch
No I meant, I tried it 6 years before and failed miserably
Ohh
I would say don't care much
remi? Never heard of it
U can look up
just one i wanted to try
UGLYclown999 on artstation to see my art@tawdry mulch
looks noice @worthy ridge
Well I do give a try ~ https://www.picuki.com/profile/grafficco
Explore @grafficco Instagram profile with posts and stories - Picuki.com
Thats my first post
What is the use of python though? In blender
For plugins
I see
??
I meant remi looked bad. Why bother use it
If your looking for modern, use PyQt else use tkinter
These are the two best out there, IMO
I mean you could use Eel and so on...
im trying to stay away from QT modules. I dont like their screwy licensing
I am not making any app for commercial purpose yet, so it is fine right now
i understand that
i mainly write for internal use at work, but i would like the option to be able to sell
Once I get into this compleletely I would use Electron or something, rather than desktop apps
tkinter it is, then
There is also WxPython
there are many and i have tried many
Yep, but I feel tkinter is best out there
been writing with appJar lately
aka - modified tkinter
Well, it is better IG
tkinter gives you the simplicity of using JUST PYTHON.
kivy uses kv files or somethting right? I havn't used it before
oh, i meant appJar. it is basically a skin over tkinter to make it "simpler"
that also means i have hit the limitations on my second app
Kivy looks cool, but yea, i would prefer a pure python interface. and something pissed me off about kivy.....i forget what.
pyforms would have been cool if it were more developed and supported
seems like you have tried alot of frameworks 😛
i went on a framework bender for about a year
like some, hate others, couldnt understand the rest
pyqt is pretty solid.
At the end of the day, tkinter can be made to look modern too. But ya limitations exist
pretty
gave up on pyside2 because any time i would install it, something would go wrong
now isnt a good time to try it then, more issues in pyside 6
tkinter is great but ugly. not just the UI but the code. not efficient at all
that is what drew me to appjar
it was a very simplified code version of tkinter. so i could pump out apps quick
I don't know about efficiency. But tkinter has every tool you would need to make a gui.
pysimplegui works well but it takes a hot minute to get used to
Well UI ugly, idk it depends on us. I was able to make this out of tkinter alone https://github.com/nihaalnz/ToDoApp
by "efficiency" i dont mean the running of the code but more the writing of it
for me at least
It is very very easy
right
everyone is different
some people love JS
i run as fast as i can as soon as i see it
:p
somethign about me and JS that just dont get along
I see
i should give tkinter and pyqt a try again.............at some point
Probably yea
too many things to do and know.........
Life..
@tawdry mulch what cursor pack is that? Its actually quite a nice one!
Mouse pointer theme rather.
too many languages/scripts to know right now
Python, excel VBA, AutoLisp, Json, sql, etc
Its just an animated cursor off the internet. TBH that is my system cursor and not the tkinter cursor. But I have used the same with tkinter windows and it works. Had to abandon it cuz unfortunately Menu does not take in cursors @digital rose
Everything comes with a benefit, atleast
Yes, i know it isnt a tkinter cursor, but could you tell me what pack it is?
havent seen it on the paycheck yet though LOL
Ah, i see, thanks.
Just to mimic razer :p
F 😂
you ever use PyScripter IDE?
I've never moved out of VSC
First Pycharm, then VSC. Casually IDLE to test some scripts
Such a heavy non beginner friendly editor...
https://www.dropbox.com/sh/8nbznpndwhas1oe/AACLiQaJQveYDVKm6sa3qxVGa?dl=0 this seems to be more updated version
yea. VSC always reminds me of notepad++
im gonna try out PyScripter for a while. I dont like how VSC keeps fucking up on me
I've never moved out of Vim.
Heard its great too
not beginner friends but very very functional (vim)