请问如何固定边界

时间:2019-04-10 11:42:50

标签: python-3.x tkinter tkinter-canvas

我做了这个小程序来向用户显示数据库,我可以看到数据库的按钮,但是当我按下它们时,画布上会出现边框

from tkinter import *

from tkinter import ttk


import mysql.connector



class mainpro():

def __init__(self):#its my database settings

    self.db = mysql.connector.connect(
        host="localhost",
        user="root",
        port=3306,
        passwd="1234"
    )
    self.mycursor = self.db.cursor()

    win2 = Toplevel()#idid top level because i did  tk before 
    # Title
    win2.title('Manipulate Database')
    # geometry
    sizex = 1000
    sizey = 700
    posx = 100
    posy = 100
    win2.wm_geometry("%dx%d+%d+%d" % (sizex, sizey, posx, posy))
    # style
    style = ttk.Style()
    style.theme_use('vista')
    style.configure('TLabel', font=('Calibri', 15))
    style.configure('TButton', font=('Calibri', 15, 'bold'))
    # menu
    menu = Menu(win2)
    m1 = Menu(menu, tearoff=0)
    menu.add_cascade(label='File', menu=m1)
    m2 = Menu(menu, tearoff=0)
    menu.add_cascade(label='DLL', menu=m2)
    m3 = Menu(menu, tearoff=0)
    menu.add_cascade(label='DML', menu=m3)
    m4 = Menu(menu, tearoff=0)
    menu.add_cascade(label='Help', menu=m4)

    m1.add_command(label='Show databases', command=lambda: showdata())
    win2.config(menu=menu)

    def showdata():
        def event(event):
            canvas.config(scrollregion=canvas.bbox("all"))

        self.mycursor.execute('SHOW DATABASES')
        list = self.mycursor.fetchall()
        canvas = Canvas(win2, width=1000, height=700)
        f1 = Frame(canvas)
        canvas.create_window((0, 0), window=f1, anchor='nw')
        scroll = Scrollbar(win2, orient="vertical", command=canvas.yview)
        scroll.pack(side="right", fill="y")
        canvas.configure(yscrollcommand=scroll.set)
        canvas.pack()
        f1.bind("<Configure>", event)

        y = 0
        for x in list:
            y += 1
            ttk.Label(f1, text=str(y) + '-').grid(column=0, row=y, padx=10, pady=10, sticky='w')
            ttk.Button(f1, text=x, width=35).grid(column=1, row=y, padx=10, pady=10, sticky='w')

    win2.mainloop()


mainpro()

请帮助

2 个答案:

答案 0 :(得分:0)

您可以尝试添加highlightthickness = 0:

canvas = Canvas(win2, width=1000, height=700, highlightthickness=0)

答案 1 :(得分:0)

尝试一下, 来源:Check

   import tkinter   # assuming Python 3 for simplicity's sake
    import tkinter.ttk as ttk 

    root = tkinter.Tk()

    f = tkinter.Frame(relief='flat')
    lF = ttk.LabelFrame(root, labelwidget=f, borderwidth=4)
    lF.grid()
    b = ttk.Button(lF, text='')
    b.grid()

    root.mainloop()

或者尝试这个

Canvas=Canvas(self,width=width/2,height=height/2,bg=bgCanvasColor,borderwidth=0, highlightthickness=0)