0
0 комментариев

Привет, помогите плиз. Нужно вывести функцию open_file в само приложение в окне как текст, а не как консоль. Кидаю два файла с кодом. один формс, второй моделс. Для понимания[apcode language=»python»]

import tkinter as tk
from tkinter import *
 from lib.models import*
from openpyxl import load_workbook
  class MainWindow(object):
     def __init__(self):
        # Widgets:
        self.__root = Tk()
        self.__frame = Frame(self.__root)
        self.__caption = Label(self.__frame)
        self.__listbox = Listbox(self.__frame)
        self.__textbox = Entry(self.__frame)
        self.__button1 = Button(self.__frame)
        self.__button2 = Button(self.__frame)
        # Models:
         # Models:
        self.__model1 = AbonentsModel()
     def config(self):
        self.__root.title('Система поиска контракта')
        self.__root.resizable(False, False)
        self.__caption.config(text='Список', font='Arial 12')
        self.__listbox.config(width=40, height=10)
        self.__textbox.config(font='Arial 12', justify='center', width=30)
        self.__button1.config(text='Добавить имя котракта в базу', font='Arial 10', width=25, )
        self.__button2.config(text='Отобразить все контракты по имени', font='Arial 10', width=25, )
            def layout(self):
        self.__frame.pack(padx=20, pady=20)
        self.__caption.pack(pady=10)
        self.__listbox.pack()
        self.__textbox.pack(pady=20)
        self.__button1.pack(pady=5)
        self.__button2.pack(pady=7)
     def bindings(self):
        self.__button1.bind('<Button-1>', self.slot1)
        self.__button2.bind('<Button-1>', self.slot2)
      def slot1(self, event):
        print(event)
        name = self.__textbox.get()
        if name != '':
            self.__model1.add_abonent(name)
            self.fill_listbox()
      def slot2(self, event):
        print(event)
        text = Text(width=25, height=5, bg="darkgreen", fg='white', wrap=WORD)
        text.pack()
        tx = self.__textbox.get()
        if tx != Text:
            self.__model1.open_file()
            #self.__fill_listbox()
        '''def fill_listbox(self):
        a = self.__model1.get_abonent()
        self.__listbox.delete(0, END)
        k = 0
        for a in abonents:
            k += 1
            item = f'{k}. {a[1]}'
            self.__listbox.insert(END, item)'''
      def show(self):
        self.config()
        self.layout()
        self.bindings()
        #self.fill_listbox()
        self.__root.mainloop()
                 from lib.drivers import DbDriver
from openpyxl import load_workbook
  class AbonentsModel(DbDriver):
     def __init__(self):
        super().__init__()
     def add_abonent(self, name: str)-> None:
        query = 'INSERT INTO Abonents (name) VALUES(?)'
        params = (name,)
        self.execute_dml_query(query, params)
        print(f"Имя: {name} -  успешно добавлено в таблицу")
      def edit_abonent(self, name: str, fid: int) -> None:
        query = 'UPDATE Abonents SET name=? WHERE id=?'
        params = (name, fid)
        self.execute_dml_query(query, params)
        print('Данные успешно изменены!')
     def delete_abonent(self, fid: int) -> None:
        query = 'DELETE FROM Abonents WHERE id=?'
        params = (fid,)
        self.execute_dml_query(query, params)
        print('Данные успешно удалены!')
     def get_abonent(self, fid: int) -> list:
        query = 'SELECT * FROM Abonents'
        params = (name,fid)
        return self.execute_dql_query(query, params)
      def create_table(self, fid: int):
        query = ('CREATE TABLE IF EXISTS core_fes(Well TEXT,'
                                                'Sample TEXT,'
                                                'Proposity FLOAT,'
                                                'Swr FLOAT) ')
         params(name, fid)
        return self.execute_dql_query()
      def open_file(self):
         wb = load_workbook('data.xlsx')
        sheets = wb.sheetnames
        sheet = wb.active
        cell = sheet["A"]
        cell = sheet.cell(row=1, column=1)
        for word in sheet[81:84]:
            string = " "
            for cell in word:
                string = str(cell.value)
                string = string.replace("0.0000", "  ")
                string = string.replace(",,,", " ")
                string = string.replace(",", " ")
                print(string)

[/apcode]

Asked question
Добавить комментарий