Это мой первый пост, так что будьте полегче со мной :)
У меня есть простой скрипт Python 2.7, который создает окно, используя overrideredirect(1)
. Это все хорошо работает, холст, который я добавляю, работает, но когда я добавляю метку и применяю ее высоту и ширину, она сильно удлиняется на обеих осях.
это происходит как для строки заголовка, так и для ярлыков выхода. Я хочу сделать их тоньше, но я не могу использовать поплавки. Есть идеи, что происходит?
Вот мой код:
from Tkinter import *
from math import *
class Main():
def __init__(self):
# Create a basic tkinter window
self.root = Tk()
self.canvas = Canvas(self.root, width=700, height=500)
self.canvas.pack()
# Start function that creates labels
self.initiate()
# Make the window frameless
self.root.overrideredirect(1)
self.root.mainloop()
def initiate(self):
# Create a single black bar across the top of the window
# My issue is here. I apply the height of 1, and it displays in the tkinter window of a height more like 10-20.
# I think it has somthing to do with overrideredirect, but i dont know what it is, i have never used it before.
self.titlebar = Label(self.canvas, width=700, height=1,
bg='black')
self.titlebar.place(x=0, y=0)
# This and the other functions make the window move when you drag the titlebar. It is a replacement for the normal title bar i removed with overrideredirect.
self.titlebar.bind("<ButtonPress-1>", self.StartMove)
self.titlebar.bind("<ButtonRelease-1>", self.StopMove)
self.titlebar.bind("<B1-Motion>", self.OnMotion)
# Create a quit button in top left corner of window
self.quit = Label(self.canvas, width=1, height=1, bg='grey')
self.quit.place(x=0, y=0)
self.quit.bind("<Button-1>", lambda event: self.root.destroy())
def StartMove(self, event):
self.x = event.x
self.y = event.y
def StopMove(self, event):
self.x = None
self.y = None
def OnMotion(self, event):
deltax = event.x - self.x
deltay = event.y - self.y
x = self.root.winfo_x() + deltax
y = self.root.winfo_y() + deltay
self.root.geometry("+%s+%s" % (x, y))
Main()