-2

I have already tried to find an answer to my question, but I haven't been successful.

I do my first try with an GUI with tkinter on Python 3.6

I create a small example for you:

import tkinter as tk
import PyQt5.QtWidgets

RateFenstergrossh=0.75
RateFenstergrossb=0.75

app = PyQt5.QtWidgets.QApplication([])  # the bug doesn't occur without this line 
screen_width = app.desktop().screenGeometry().width()
screen_height = app.desktop().screenGeometry().height()

def vp_start_gui():
    global root
    root = tk.Tk()
    top = Toplevel1(root)
    root.mainloop()

class Toplevel1:
    def __init__(self, top=None):
        top.geometry("+%d+%d"%(screen_width/2 - screen_width*RateFenstergrossb/2, screen_height/2 - screen_height*RateFenstergrossh/2))

        self.Entry = tk.Entry(top)
        self.Entry.pack(padx=20,pady=20)

if __name__ == '__main__':
    vp_start_gui()

If you type some characters and try to delete them with backspace a small rectangle appears in the entry line. If you print this character the program prints <0x08>. If I do not use the package import PyQt5.QtWidgets and the funktion PyQt5.QtWidgets.QApplication([]) the bug doesn't occur.

I do not really understand this bug. Maybe somebody can help me with this.

Zaby1990
  • 21
  • 6
  • 1
    Why are you trying to use both Tkinter and Qt in one program? Those are two entirely separate approaches to writing GUIs. – jasonharper Mar 17 '20 at 20:44
  • ***"not use PyQt5 ... the bug doesn't occur."***: That's the reason **not** to do so. Why have you choosen to mix this two modules? – stovfl Mar 17 '20 at 20:53
  • I tried this because I found this solution to center the windows at https://stackoverflow.com/questions/3352918/how-to-center-a-window-on-the-screen-in-tkinter – Zaby1990 Mar 17 '20 at 21:18
  • Maybe if you understand the problem, you do know a better solution to center the window on screen or to read the screen size without PyQt5 – Zaby1990 Mar 17 '20 at 21:24

1 Answers1

0

Thanks to the two comments. I have learned never mix tkinter and PyQt. My solution is now.

import tkinter as tk

RateFenstergrossh=0.75
RateFenstergrossb=0.75

def vp_start_gui():
    global root
    root = tk.Tk()
    screen_width = root.winfo_screenwidth()
    screen_height = root.winfo_screenheight()
    top = Toplevel1(root)
    root.mainloop()

class Toplevel1:
    def __init__(self, top=None):
        top.geometry("+%d+%d"%(screen_width/2 - screen_width*RateFenstergrossb/2, screen_height/2 - screen_height*RateFenstergrossh/2))

        self.Entry = tk.Entry(top)
        self.Entry.pack(padx=20,pady=20)

if __name__ == '__main__':
    vp_start_gui()

Solution: I have to read the screensize with

screen_width = root.winfo_screenwidth()
screen_height = root.winfo_screenheight()
Zaby1990
  • 21
  • 6