Tkinter .get() not working in PyScripter 42.0.0 x64 - Python 3.10

13 views
Skip to first unread message

John Wardley

unread,
Nov 9, 2022, 3:00:36 PM11/9/22
to PyScripter
Please see coding below.   This code works in Python IDLE but doesn't work in PyScripter. 
After data entry, processing occurs then the data entry field should be cleared ready for the next entry.  But in PyScripter the field expense type isn't printed and isn't cleared.
Is the problem in my coding or is it in PyScripter?

# Etsy Expenses.py
import tkinter as tk
from tkinter import *
from tkinter.ttk import *

# create basic window
window = Tk()
window.title("Etsy Expenses")
window.geometry('500x600')
initemtype=StringVar()
initemtype.set("")
#########################################################
###
#                  Input Expenses to Excel
###

def setTextInput():
    import openpyxl
    from datetime import datetime as dt
    from openpyxl import Workbook
    from openpyxl.styles import Alignment
    from openpyxl.styles import Font
    from openpyxl import load_workbook
    import tkinter as tk
    from tkinter import ttk
    expense=initemtype.get()
##################################################
    print('39')
    print(expense)    #  from initemtype.get()
##################################################
    expenses_match = 0
###################################################################
###
#      Expenses
###
    if expenses_match == 1:
######################################
#
#    Do processing
#
######################################

######################################
#
#    Clear date entry fields
#
######################################
        initemtype.set("")


##########################################################
####
#        No Match Expense
####
    if expenses_match != 1:
        print('74')
        print(expense)
######################################
#
#    Do processing
#
######################################

######################################
#
#    Clear date entry fields
#
######################################
        initemtype.set("")

##########################################################
###
#      Input Data using Tkinter
###

def data_in():
    import tkinter as tk
    expenses = [
     "Other Expense",                                                             #  G
     "Delivery to UK",                                                                 #  H
     "UK Postage",                                                                     #   I
     "Envelopes",                                                                         #  J
     "Cards",                                                                                 #  K
     "Design",                                                                                   #  L
     "Etsy Listing Fee",                                                                        #   M
     "Etsy Processing Fee",                     # 4% of order total + 20p                            N
     "Etsy Transaction Fee",                   # 5% of item total                                     O
     "Etsy Postage Transaction Fee",       # 5% of postage total                                       P
     "Etsy Regulatory Operating Fee",      # 0.25% of total order  ex VAT                            Q
     "UK VAT",                                                                                 #    R
     "Sales Tax",                                                                             #   S
     "Refund",                                                                              #  T
     "Drawings",                                                                         # U
     "Payment Received",                                                          #  W
     "Etsy VAT Listing Fee",                                                  #   V
     "Etsy VAT Auto Renew",                                                # X
     "Etsy VAT Processing Fee",                                          # Y
     "Etsy VAT Transaction Fee",                                       # Z
     "Etsy VAT Shipping Trans Fee",                                # AA
     "Etsy VAT Reg Op Fee"                                       # AB
     ]
    Label(window, text="Etsy Expenses", font=("calibri", 14)).pack()         # label centre top
    ent4val = expenses
    lab4=Label(window, text="Expense Type")
    lab4.place(x=60, y=140)
    ent4=Combobox(window, value = ent4val, textvariable=initemtype)
    ent4.place(x=60, y=160, width = 160)
    ent4.bind("<<ComboboxSelected>>")
    test_button=Button(window, text='Submit', command=lambda:setTextInput())
    test_button.place(x=100, y=500)
    end_button=Button(window, text='   Exit   ', command=quit)
    end_button.place(x=315, y=500)

##############################################################
###
#      Programme Flow
###
data_in()


PyScripter

unread,
Nov 9, 2022, 4:02:44 PM11/9/22
to PyScripter
Your program as it stands, will not run as expected from the python prompt nor from most of the IDEs.  This is because it does not have a main loop.  

A typical tkinter application has the following (notice the last statement):

from tkinter import * 
window = Tk() 
window.title("Welcome to LikeGeeks app") 
lbl = Label(window, text="Hello") 
lbl.grid(column=0, row=0) 
window.mainloop()

Your script runs OK within IDLE because IDLE is a tkinter app and has a main loop.  PyScripter offers something similar.   A specialized Tk python engine.    

Try Run, Python Engine, Remote (Tk)

After that your script will run.

Let me just add that this is not recommended.  It is better to have a compete tkinter app and run it with the standard Remote engine.  This wiki page provides explains the python engine choices.
Reply all
Reply to author
Forward
0 new messages