0

I have a Tkinter (3.8) program. When testing it in IDLE I select "Show report" from the menu and it automatically uses the IDLE Shell to output the data. I can then print the data from the Shell. However, when I open the program from a desktop shortcut and I select "Show report" it does not open any Shell to output the data and consequently I cannot print the formatted data. The code for the Run_Report which is called from the menu item "Show report" is shown below. What should I add to it to open the IDLE Shell window to display the data?

def Run_Report():

    sPrinciple=e_SelectInv.get()

    Sql=("SELECT Principle as Investment, RptDate as Report_Date, printf('%,.2f',RptVal) as Report_Value, printf('%.2f',ExchRate) as Exchange_Rate, printf('%,d',RptVal*ExchRate) as Total_Value FROM MyInv WHERE Principle = ?" +
             "order by Id Asc")

    conn = sqlite3.connect(r'/home/bushbug/Databases/TrackMyInv')
    curs = conn.cursor()
    curs.execute(Sql,(sPrinciple,)) 
    col_names = [cn[0] for cn in curs.description]
    rows = curs.fetchall()
     
    x = PrettyTable(col_names)
    x.align[col_names[0]] = "l"
    x.align[col_names[1]] = "r"
    x.align[col_names[2]] = "r"
    x.align[col_names[3]] = "r"
    x.align[col_names[4]] = "r"
    x.padding_width = 1
    
    for row in rows:
        x.add_row(row)
    
    print (x)
    tabstring = x.get_string()
    output=open("export.txt","w")
    output.write("Population Data"+"n")
    output.write(tabstring)
    output.close()

Help will be greatly appreciated.

  • Where in your script are you calling/using Tkinter? It is not in your code above. – Niels Henkens Feb 04 '21 at 10:49
  • Gosh Niels, you have asked me an awkward question. At the start of the program I import various Tkinter items from tkinter import ttk from tkcalendar import Calendar, DateEntry import sqlite3 import datetime as dt from tkinter import messagebox as msgbox from prettytable import PrettyTable import subprocess, sys I am under the impression that somewhere in the Run_Report function I should somehow call/open IDLE Shell? Am I missing something? – Frank Aldridge Feb 04 '21 at 16:16
  • And you say "when I open the program from a desktop shortcut". How do you open it with a desktop shortcut? Have you compiled the script into an exe (with pyinstaller or something) or do you open it with python? – Niels Henkens Feb 04 '21 at 16:20
  • There is also the option of "printing" to a tkinter window if that suits your needs. See: https://stackoverflow.com/questions/55598137/priting-output-in-tkinter-instead-of-console – Niels Henkens Feb 04 '21 at 16:21
  • Just as an update. I created a .desktop file in the same folder as the .py file. I then copied the .desktop file to the Desktop and set it to "Allow launching". That worked fine but when I tried to run a report there was no editor. So I added the following: Import subprocess and the following statement: subprocess.Popen(['/usr/bin/idle-python3.8',"export.txt","w"]). Now when I run the program from the desktop and click Run Report the Python Shell opens with all of the data and I can then Print it to my printer from there. Thanks for your interest. – Frank Aldridge Feb 06 '21 at 15:22

0 Answers0