style sheet remove border of window - pyqt

is it possible to remove border of window using "style sheet" in qt designer ?
i have to remove it within qt designer, and i dont want to convert it into python.

The easiest way to control your window border would be setting window flags parameter in the constructor, smth like this:
class MainWindow(QtGui.QMainWindow):
def __init__(self, parent = None):
super(MainWindow, self).__init__(parent, QtCore.Qt.FramelessWindowHint)
or call:
your_window.setWindowFlags(QtCore.Qt.CustomizeWindowHint)
for your window anywhere in the code.
hope this helps, regards

Related

Why does a borderless Kivy Window shift content down and to the right?

Using Kivy, I want to remove the default border from the App window (removing the close, minimize and maximize buttons). Based on the Kivy docs, I want to set the borderless value of my Window to True. However, doing so moves the content of my window down and to the right, exposing the black background color on the top and left sides of the window.
Screenshot of Window with borderless=False
Screenshot of Window with borderless=True
In the above images, the white within the window is coming from the Window.clearcolor, and the black in the borderless=True image is what I want to remove, or overlay with the rest of my content.
In the following snippet I have removed all the code that makes up the inner widgets of the kivy App, replacing them with an empty GridLayout to show where the content will be.
from kivy.app import App
from kivy.uix.gridlayout import GridLayout
from kivy.core.window import Window
class MyApp(App):
def build(self):
self.title = 'My App'
Window.clearcolor = (1, 1, 1, 1)
Window.size = (300, 430)
Window.borderless = True # This is what is being changed
return GridLayout()
if __name__ == '__main__':
MyApp().run()
I have read the answers to similar questions regarding removing the default Kivy window border and how to position a borderless Kivy window.
Can anyone help diagnose how to shift the contents of my window back to the upper left corner when borderless is set to True?
Note: This is my first Stackoverflow question, please let me know how to improve it if need be!
Well, I'm not sure what the exact issue was, but after troubleshooting several different things within PyCharm (where my original project files were held), on a whim I tried opening the same project with Sublime and the issue is no longer present. When I run the identical code in Sublime, I get the intended result:
Beautiful! Just how I wanted it. =) I'm sure I somehow goofed up the Kivy settings in Pycharm somehow without realizing it, maybe something with the builder strings? I'm honestly at a loss. But I suppose if by any off chance someone else comes across this, switch up your IDE for a clean slate and give it another go.

Weird white Stripe appearing next to tkinter scrollbar

So while 'designing' my tkinter application i noticed this white stripe appearing next to the scrollbar there:
It is not disappearing when the scrollbar gets to an active state but it is definetly part of the Scrollbar itself because there is nothing under it in my programm which has a white background.
It seems to appear no matter if I use grid or pack. In this case I use grid - here the little extract of my code:
class App(Tk):
def __init__(self):
#other stuff
self.hvf=hvFrame(self,sticky=EW,showfocus=S,bg='white',padx=5,pady=5)
self.hvf.grid(row=1,column=0,columnspan=2,sticky=NSEW,pady=5,padx=(0,5))
sb=Scrollbar(self,orient=VERTICAL,command=self.hvf.yview,bd=0,highlightthickness=0)
sb.grid(row=1,column=2,sticky=NSEW,pady=5)
self.hvf.config(yscrollcommand=sb.set)
If you ned more, then here you go. (Should not be executable for you because you do not have the extras file but you should still be able to understand it.)
EDIT:
A little reproduceable example:
from tkinter import Tk,Frame,Scrollbar,VERTICAL,NS
root = Tk()
frame = Frame(root,height=300,width=500)
frame.grid(row=0,column=0,padx=(0,5),pady=5)
sb = Scrollbar(root,orient=VERTICAL)
sb.grid(row=0,column=1,sticky=NS,pady=5)
root.mainloop()
After testing a few things like changing the windows theme or changing the root and frame background to black the while line still comes up. I cannot be 100% sure but I believe this is due to fact that tkinter on Windows pulls the scrollbar design from Windows itself and it is simply part of that design. It may be a design choice to give the scroll bar some visual depth. That said you cannot do anything to change the design of the scrollbar within a Windows environment so you as stuck with this unless you write a custom scrollbar.
Example code:
import tkinter as tk
root = tk.Tk()
root['bg'] = 'black'
frame = tk.Frame(root, height=300, width=500, background='black')
frame.grid(row=0, column=0)
sb = tk.Scrollbar(root, orient=tk.VERTICAL)
sb.grid(row=0, column=1, sticky=tk.NS)
root.mainloop()
Results from overlay of white and black backgrounds:
Below is the code I use for a custom scrollbar (but did not write myself). You can find the post where I got the code here.

binding keyboard events tkinter

Still quite new at python , i'm learning tkinter.
I would like to use keyboard events rather than mouse events for some fonction.
However keyboard events do not work although mouse events do.
here is a very simple example of what is not working. Using button 1 with the mouse and pressing key 'z on the keyboard should do the same, but the keyboard does nothing. I have tried to read tkinter documentation but didn't find the answer.
thanks for your help
from tkinter import *
class Pipi(Frame):
def __init__(self,master=None):
Frame.__init__(self,width=400,height=400,bg='red')
self.pack()
self.bind("<z>",self.do)
self.bind("<Button-1>", self.do)
def do(self,event):
print('la vie est belle')
root=Tk()
Pipi(root)
root.mainloop()
This is due to Frame widget not having the focus. With the mouse event, it works seemingly different. There can be a couple of workarounds:
Grabbing the focus before the event happens
binding to something else
To achieve the first, simply add:
self.focus_set()
somewhere inside __init__.
To achieve the second, replace:
self.bind("<z>",self.do)
with:
self.master.bind('<z>', self.do)

Python3 tkinter lay invisible scrollbar over widget?

I would like to lay an invisible scrollbar over a Treeview
I am using a raspberry pi and have a small touchscreen and I thus would like to use the space efficiently
I had to size up my scrollbar as I couldn't figure out how to make "swipe"-scrolling in a treeview possible
That's why I now have very little space and the font is almost too small
Is there any way to make a scrollbar invisible, but still usable when laying on another widget with eg. the place function?
You don't need scrollbars to scroll. All scrollable widgets have an api that is used for scrolling: the xview and yview methods. The scrollbar is just a convenient way to call those methods, but it's not the only way.
I don't know what events a swipe will send, but you can bind to those events and directly call the xview and/or yview methods yourself.
For example, let's assume for the moment that a touch is the <B1> event, and a swipe is the <B1-Motion> event. You can scroll with a swiping motion like this:
class Example:
def __init__(self):
...
self.tree = ttk.Treeview(...)
self.tree.bind("<B1>", self.start_swipe)
self.tree.bind("<B1-Motion>", self.on_swipe)
...
def start_swipe(self, event):
self.last_y = event.y
def on_swipe(self, event):
# only do the scrolling if the swipe is 10 pixels or more
if abs(event.y - self.swipe_start) < 10:
return
# compute whether we are scrolling up or down
delta = -1 if event.y > self.last_y else 1
# remember this location for the next time this is called
self.last_y = event.y
# do the scroll
self.tree.yview_scroll(delta, "units")

Python Tkinter Clickable Text?

I'm wondering if there's a way to make clickable text in Tkinter. Maybe like you would see on a title screen of a game, and where you hover your mouse over the text and it changes color/hightlights itself. All I need the click to do is execute another function.
Are either of these things possible? Thanks!
you are looking for tkinter's events:
tk_widget.bind("<Button-1>",CALLBACK)
The call back needs to take an event argument which is a dictionary containing information about what triggered the event.
This can run into issues with widgets that overlap such as windows in a canvas or labels sometimes triggering the callback for the window behind it.
For hovering the mouse over a widget the event is called "<Enter>" and moving mouse out of widget region is called "<Leave>" for highlighting text effect, if you just want to capture a click anywhere on a window then on the root call root.bind_all("<Button-1>",CALLBACK)
source: http://infohost.nmt.edu/tcc/help/pubs/tkinter/web/index.html
http://infohost.nmt.edu/tcc/help/pubs/tkinter/web/events.html
example:
try:
import tkinter as tk
except ImportError:
import Tkinter as tk
def change_case(event=None):
new_text = str.swapcase(lab["text"])
lab.config(text=new_text)
def red_text(event=None):
lab.config(fg="red")
def black_text(event=None):
lab.config(fg="black")
root = tk.Tk()
lab = tk.Label(root,text="this is a test")
lab.bind("<Button-1>",change_case)
lab.bind("<Enter>",red_text)
lab.bind("<Leave>",black_text)
lab.grid()
root.mainloop()
hope this helps :)

Resources