Scrollen mit notebook und canvas

Fragen zu Tkinter.
Antworten
roy-lueders
User
Beiträge: 8
Registriert: Montag 5. Februar 2018, 15:12

Hi Leute,

folgende Probleme habe ich.
Einmal soll mir mittels canvas mein tabs scollbar sein, wenn der Inhalt zu groß ist für die Ansicht.
Und zum anderen bekomm ich das Canvas nicht ohne padding hin (obwohl es auf 0 steht).

Code: Alles auswählen

# -*- coding: utf-8 -*-
#import Tkinter as Tk
import ttk
import tkMessageBox
import Tkinter as tk
##from Tkinter import *
import ConfigParser 
import sqlite3
import tkFont
import subprocess
from PIL import ImageTk, Image
from functools import partial
import os

PROGRAMM = 'AnyDesk Manager Pro'
VERSION = '1.1'
AUTHOR = 'Roy Lüders'
COPYRIGHT = '2018'

## config ##
if "Pro" in PROGRAMM:
    MAIN_BG = '#333'
else:
    MAIN_BG = '#fff'
    
NORMAL_BG = '#5bc0de'
NORMAL_FG = '#ffffff'
NORMAL_AF = '#ffffff'
NORMAL_AB = '#269abc'
ABOUT_BG = MAIN_BG
ABOUT_AF = MAIN_BG
## config end ##

config_file = str('config.ini')

if os.path.exists(config_file):
    config_db = ConfigParser.RawConfigParser()
    config_db.read("config.ini") 
    db_path = config_db.get("DB", "path")
else:
    db_path = 'res/database.db'

##print db_path

def about():
    tkMessageBox.showinfo("Über "+ PROGRAMM, "Version: " + VERSION + "\n\n" + "Copyright " + COPYRIGHT + " by " + AUTHOR)

def start(adresse, passwort):
##    args = 'echo ' + passwort +' | "res/AnyDesk.exe" "' + adresse + '" --with-password'
####    subprocess.call(args, stdout=None, stderr=None, shell=False)
    process = subprocess.Popen(["res/AnyDesk.exe", adresse, "--with-password"], stdin=subprocess.PIPE)
    process.stdin.write(passwort + "\n")
    

def verbindungen(tab,pc):
    con = sqlite3.connect(db_path)
    with con:
        cur = con.cursor()
        cur.execute("SELECT * FROM anydesk WHERE pc = '" + pc + "' ORDER BY hotel ASC")
        rows = cur.fetchall()
	
        frame = tk.Frame(tab,bg=MAIN_BG)
        frame.grid(row=0, column=0,padx=0, pady=15)

        displaybreite = main.winfo_screenwidth()
        zwischenbreite = 210
        spalten = 6

        spaltenbreite6 = displaybreite - zwischenbreite
        spaltenbreite = spaltenbreite6 / spalten

        rowing = 0
        rowing2 = 1
        rowing3 = 2
        columning = 0

        for row in rows:
            adress_id = row[0]
            adresse = row[1]
            passwort = row[2]
            hotel_name = row[4]
            hotel_fix = str(row[5])
            server = row[6]

            if columning == spalten:
                rowing += 1
                rowing2 += 1
                rowing3 += 1
                columning = 0

            group = tk.Frame(frame)
            group.grid(row=rowing, column=columning, padx=15, pady=(0,15), sticky='S')

            image = Image.open("res/img/hotel/"+hotel_fix+".jpg")
            photo = ImageTk.PhotoImage(image)
            foto = tk.Label(group, image=photo,bd=0, width=spaltenbreite)
            foto.image = photo # keep a reference!
            foto.grid(row=rowing, column=columning, padx=0, pady=0)

            if server == 1:
                server_img = ImageTk.PhotoImage(file ="res/img/server.gif")
                server = tk.Label(group, image = server_img)
                server.image = server_img
                server.grid(row=rowing, column=columning, padx=0, pady=0, sticky='NE')

            helv36 = tkFont.Font(weight=tkFont.BOLD)

            label = tk.Label(group, text=hotel_name, font=helv36,background='#555',foreground='#fff')
            label.grid(row=rowing2, column=columning, padx=0, pady=0, sticky='NSWE')
            
            play_button = tk.Button(group, font=helv36, takefocus=False, bg=NORMAL_BG, fg=NORMAL_FG, activebackground=NORMAL_AB, activeforeground=NORMAL_AF, bd=0, pady=15, text="Starten",command=partial(start, adresse, passwort))
            play_button.grid(row=rowing3, column=columning, padx=0, pady=0, sticky='NSWE')

            columning += 1

        cur.close()      

main = tk.Tk()
main.title(PROGRAMM)
main.iconbitmap('res/img/icn.ico')
main.state('zoomed')

Can1 = tk.Canvas(main, bg="Yellow")
Can1.grid(row=0, column=0, columnspan=49, padx=0, pady=0)
        
vsbar = tk.Scrollbar(main, orient="vertical", command=Can1.yview)
vsbar.grid(row=0, column=50, padx=0, pady=0, sticky='NESW')
Can1.configure(yscrollcommand=vsbar.set)

# gives weight to the cells in the grid
rows = 0
while rows < 50:
    main.rowconfigure(rows, weight=1)
    main.columnconfigure(rows, weight=1)
    rows += 1

FONT_HEAD = tkFont.Font(size=15)
noteStyler = ttk.Style()
noteStyler.configure('.',font=FONT_HEAD)
noteStyler.configure("TNotebook", background=MAIN_BG, borderwidth=0)
noteStyler.configure("TNotebook.Tab", background=MAIN_BG, foreground='#000',borderwidth=0)
noteStyler.configure("TFrame", background=MAIN_BG, foreground='#fff', borderwidth=0)

# Defines and places the notebook widget
nb = ttk.Notebook(Can1,style='TNotebook')
nb.grid(row=1, column=0, columnspan=25, rowspan=25, sticky='NESW',padx=15, pady=15)
##
if "Pro" in PROGRAMM:
    # Adds tab 3 of the notebook
    tab3 = ttk.Frame(nb)
    lab = 'EDV'
    nb.add(tab3, text=lab)
    verbindungen(tab3,lab)

# Adds tab 1 of the notebook
tab1 = ttk.Frame(nb)
lab = 'Backoffice'
nb.add(tab1, text=lab)
verbindungen(tab1,lab)

# Adds tab 2 of the notebook
tab2 = ttk.Frame(nb)
lab = 'Frontoffice'
nb.add(tab2, text=lab)
verbindungen(tab2,lab)

about_button = tk.Button(main,bg=ABOUT_BG, activebackground=ABOUT_AF, bd=0, text="About", command=about)
about_img = ImageTk.PhotoImage(file="res/img/about.gif")
about_button.config(image=about_img)
about_button.grid(column=49, sticky='E',padx=15, pady=(0,15))

main.configure(bg=MAIN_BG)
main.mainloop()


Antworten