Converting Python3 script to .exe with cx_Freeze, attribute error - python

Writing my first Python application and my first post here.
I am running windows 10 with Python 3.7 and cx_Freeze version 5.1.1.
Once I've run the setup build and I double click the executable file I am meet with the error: AttributeError: 'NoneType' object has no attribute 'write'.
I can't seem to figure it out myself.
(Also having problem with the picture that can't be found, so I commented it out in the script just to work on one issue at a time)
Tbh I am not sure where to start, I believe the error is thrown because of the write to textbox code:
def decorator(func):
def inner(inputStr):
try:
textbox.insert(INSERT, inputStr)
return func(inputStr)
except:
return func(inputStr)
return inner
sys.stdout.write=decorator(sys.stdout.write)
This is the script I've created.
from tkinter import *
from PIL import Image, ImageTk
root = Tk()
root.title("Ghost task")
root.geometry("640x640+0+0")
#Image load
#load = Image.open('Ghost.png')
#ghost = ImageTk.PhotoImage(load)
#img = Label(root, image=ghost)
#img.image = ghost
#img.place(x=0, y=0)
#Text
heading = Label(root, text="Finish workflow script", font =("arial", 20, "bold"), fg="steelblue").place(x=200, y=0)
label1 = Label(root, text="Provide the wf_group:", font =("arial", 12, "bold"), fg="steelblue").place(x=200, y=80)
label2 = Label(root, text="Provide the client:", font =("arial", 12, "bold"), fg="steelblue").place(x=200, y=103)
label3 = Label(root, text="Provide the user:", font =("arial", 12, "bold"), fg="steelblue").place(x=200, y=126)
label4 = Label(root, text="Provide the voucher no:", font =("arial", 12, "bold"), fg="steelblue").place(x=200, y=149)
bottom = Label(root, text="Version 1.01", font = ("arial", 6, "bold"), fg="black").place(x=580, y=625)
#Boxes
wfgroup = StringVar()
client = StringVar()
user = StringVar()
voucher = StringVar()
entry_box = Entry(root, textvariable=wfgroup, width=28, bg="lightgreen").place(x=445, y=85)
entry_box = Entry(root, textvariable=client, width=28, bg="lightgreen").place(x=445, y=107)
entry_box = Entry(root, textvariable=user, width = 28, bg="lightgreen").place(x=445, y=129)
entry_box = Entry(root, textvariable=voucher, width = 28, bg="lightgreen").place(x=445, y=151)
#Results
def do_mssql():
textbox.delete('1.0', END)
textbox.update()
print("Removed some useless information")
def do_oracle():
textbox.delete('1.0', END)
textbox.update()
print("Removed some useless information")
#Buttons
work = Button(root, text="MsSQL Buu", width=30, height=5, bg="pink", command=do_mssql).place(x=50, y=200)
work2 = Button(root, text="Oracle Buu", width=30, height=5, bg="pink", command=do_oracle).place(x=360, y=200)
#Text output
textbox=Text(root, width = 77, height = 20)
textbox.place(x=10, y=300)
def decorator(func):
def inner(inputStr):
try:
textbox.insert(INSERT, inputStr)
return func(inputStr)
except:
return func(inputStr)
return inner
sys.stdout.write=decorator(sys.stdout.write)
root.mainloop()
Appreciate any help I can get.
//Fred

Figured it out.
It was the .write that caused the issue.
I rewrote the script a bit.
Did not need to but that's how I solved it.
def do_mssql():
textbox.delete('1.0', END)
textbox.update()
sys.stdout("--This script is for MsSQL--\n")
def redirector(inputStr):
textbox.insert(INSERT, inputStr)
sys.stdout = redirector
Removed .write from sys.stdout.write
Changed the print() to sys.stdout and it worked. :)
//Fred

Related

how to fix AttributeError: 'NoneType' object has no attribute 'group' error in google translator

i am building a google translator with tkinter and googletrans, and everything looks good and works well until i added the last part of it that handles what happens when you press the translator button, that is, this function:
def translate_now():
text_ = text1.get(1.0, END)
t1 = Translator()
trans_text = t1.translate(text_, src=combo1.get(), dest=combo2.get())
trans_text = trans_text.text
text2.delete(1.0, END)
text2.insert(END, trans_text)
it then gives me this error when i run it:
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Users\FSTC\AppData\Local\Programs\Python\Python310\lib\tkinter\__init__.py", line 1921, in __call__
return self.func(*args)
File "C:\Users\FSTC\Downloads\translator\main.py", line 24, in translate_now
trans_text = t1.translate(text_, src=combo1.get(), dest=combo2.get())
File "C:\Users\FSTC\Downloads\translator\venv\lib\site-packages\googletrans\client.py", line 182, in translate
data = self._translate(text, dest, src, kwargs)
File "C:\Users\FSTC\Downloads\translator\venv\lib\site-packages\googletrans\client.py", line 78, in _translate
token = self.token_acquirer.do(text)
File "C:\Users\FSTC\Downloads\translator\venv\lib\site-packages\googletrans\gtoken.py", line 194, in do
self._update()
File "C:\Users\FSTC\Downloads\translator\venv\lib\site-packages\googletrans\gtoken.py", line 62, in _update
code = self.RE_TKK.search(r.text).group(1).replace('var ', '')
AttributeError: 'NoneType' object has no attribute 'group'
below is my full source code for more clarity:
from tkinter import *
from tkinter import ttk, messagebox
import googletrans
from googletrans import Translator
root = Tk()
root.title("Google Translator")
root.geometry("1080x400")
root.resizable(False, False)
root.configure(background="white")
def label_change():
c = combo1.get()
c1 = combo2.get()
label1.configure(text=c)
label2.configure(text=c1)
root.after(1000, label_change)
def translate_now():
text_ = text1.get(1.0, END)
t1 = Translator()
trans_text = t1.translate(text_, src=combo1.get(), dest=combo2.get())
trans_text = trans_text.text
text2.delete(1.0, END)
text2.insert(END, trans_text)
# icon
image_icon = PhotoImage(file="images.png")
root.iconphoto(False, image_icon)
# arrow
arrow_image = PhotoImage(file="arrow.png")
image_label = Label(root, image=arrow_image, width=150)
image_label.place(x=460, y=50)
language = googletrans.LANGUAGES
languageV = list(language.values())
lang1 = language.keys()
# first combobox
combo1 = ttk.Combobox(root, values=languageV, font="Roboto 14", state="r")
combo1.place(x=110, y=20)
combo1.set("ENGLISH")
label1 = Label(root, text="ENGLISH", font="segoe 30 bold", bg="white", width=18, bd=5, relief=GROOVE)
label1.place(x=10, y=50)
# second combobox
combo2 = ttk.Combobox(root, values=languageV, font="Roboto 14", state="r")
combo2.place(x=730, y=20)
combo2.set("SELECT LANGUAGE")
label2 = Label(root, text="ENGLISH", font="segoe 30 bold", bg="white", width=18, bd=5, relief=GROOVE)
label2.place(x=620, y=50)
# frame 1
f = Frame(root, bg="black", bd=5)
f.place(x=10, y=118, width=440, height=210)
text1 = Text(f, font="Robote 20", bg="white", relief=GROOVE, wrap=WORD)
text1.place(x=0, y=0, width=430, height=200)
scrollbar1 = Scrollbar(f)
scrollbar1.pack(side="right", fill="y")
scrollbar1.configure(command=text1.yview)
text1.configure(yscrollcommand=scrollbar1.set)
# frame 2
f1 = Frame(root, bg="black", bd=5)
f1.place(x=620, y=118, width=440, height=210)
text2 = Text(f1, font="Robote 20", bg="white", relief=GROOVE, wrap=WORD)
text2.place(x=0, y=0, width=430, height=200)
scrollbar2 = Scrollbar(f1)
scrollbar2.pack(side="right", fill="y")
scrollbar2.configure(command=text2.yview)
text2.configure(yscrollcommand=scrollbar2.set)
# button to translate
translate = Button(root, text="Translate", font=("Roboto", 15), activebackground="white", cursor="hand2",
bd=1, width=10, height=2, bg="black", fg="white", command=translate_now)
translate.place(x=476, y=250)
label_change()
root.mainloop()
am suspecting it may be having problems connecting to google translator or something similar. but what could be the problem precisely?
you are getting this error because you dont have updated version of googletrans,
so use update version of googletrans :
Command to install update version: "pip install googletrans==3.1.0a0"
This will solve your problem.

How to compile python EXE script that can be used on windows computer without python programme

I am struggling ensure python script work on windows computer that does not have python installer. The script below only works on the computer with python software not sure where l am going wrong. Result is if uploaded on another computer no pictures or path is wrong. l am new to python can you please help as l dont know where l am going wrong. Thanks in advance
"""
from tkinter import*
import tkinter as tk
from tkinter import ttk
from datetime import datetime
windo = Tk()
windo.resizable(width=FALSE, height=FALSE)
windo.geometry("600x400")
windo.iconbitmap(r"C:\Users\breada\OneDrive\Desktop\Notes\image\Healthcare.ico")
house = "Mhungu"
def han():
print("Forms to be completed")
import tkinter as tk
from tkinter import ttk
from datetime import datetime
root = Tk()
root.resizable(width=FALSE, height=FALSE)
root.geometry("680x670")
root.iconbitmap(r"C:\Users\breada\OneDrive\Desktop\Notes\image\Healthcare.ico")
house = "Mhungu"
fun8 = Label(root, text="Running times comp :")
fun8.place(x=10,y=120)
var32 = IntVar()
chekbtn_1 = Checkbutton(root ,text="Yes", variable=var32)
chekbtn_1.place(x=180,y=120)
var33 = IntVar()
chekbtn_2 = Checkbutton(root ,text="No", variable=var33)
chekbtn_2.place(x=230,y=120)
def cli(value):
print("Severity of aggression")
print(value)
def clic(value):
print("Area of aggression")
print(value)
def click(value):
print("Nature of aggression")
print(value)
def save_funct():
print("Saved")
frame = LabelFrame(root, padx=5, pady=5)
v = tk.StringVar()
v.set("None")
lab2 = Label(frame, text="Select Level of Aggression", fg="blue", font=("Arial", 10))
lab2.pack()
radioButton1 = Radiobutton(frame, variable=v,value="1-No Concern", text="1-No Concern", command=lambda:cli(v.get()))
radioButton2 = Radiobutton(frame, variable=v, value="2-Not Severe",text="2-Not Severe",command=lambda:cli(v.get()) )
radioButton3 = Radiobutton(frame, variable=v, value="3-Slightly Severe",text="3-Slightly Severe",command=lambda:cli(v.get()) )
radioButton4 = Radiobutton(frame, variable=v, value="6-Extremely Severe",text="6-Extremely Severe",command=lambda:cli(v.get()) )
radioButton5 = Radiobutton(frame, variable=v,value="5-Severe", text="5-Severe", command=lambda:cli(v.get()))
radioButton6 = Radiobutton(frame, variable=v,value="4-Fairly Severe", text="6-Fairly Severe", command=lambda:cli(v.get()))
radioButton1.pack(side=LEFT)
radioButton2.pack(side=LEFT)
radioButton3.pack(side=LEFT)
radioButton4.pack(side=RIGHT)
radioButton5.pack(side=RIGHT)
radioButton6.pack(side=RIGHT)
frame.place(x=35, y=155)
frame1 = LabelFrame(root, padx=5, pady=5)
vv = tk.StringVar()
vv.set("None")
lab2 = Label(frame1, text="Areas of Aggressions", fg="blue", font=("Arial", 10))
lab2.pack()
radioButton1 = Radiobutton(frame1, variable=vv,value="Lounge", text="Lounge", command=lambda:clic(vv.get()))
radioButton2 = Radiobutton(frame1, variable=vv, value="Kitchen",text="Kitchen",command=lambda:clic(vv.get()) )
radioButton3 = Radiobutton(frame1, variable=vv, value="Bedroom 1",text="Bedroom 1",command=lambda:clic(vv.get()) )
radioButton4 = Radiobutton(frame1, variable=vv, value="Bedroom 2",text="Bedroom 2",command=lambda:clic(vv.get()) )
radioButton5 = Radiobutton(frame1, variable=vv,value="Bedroom 3", text="Bedroom 3", command=lambda:clic(vv.get()))
radioButton6 = Radiobutton(frame1, variable=vv,value="Dinning ", text="Dinning", command=lambda:clic(vv.get()))
radioButton1.pack(side=LEFT)
radioButton2.pack(side=LEFT)
radioButton3.pack(side=LEFT)
radioButton4.pack(side=RIGHT)
radioButton5.pack(side=RIGHT)
radioButton6.pack(side=RIGHT)
frame1.place(x=35, y=255)
frame2 = LabelFrame(root, padx=5, pady=5)
vvv = tk.StringVar()
vvv.set("None")
lab2 = Label(frame2, text="Nature of Aggression", fg="blue", font=("Arial", 10))
lab2.pack()
radioButton1 = Radiobutton(frame2, variable=vvv,value="Punching", text="Punching", command=lambda:click(vvv.get()))
radioButton2 = Radiobutton(frame2, variable=vvv, value="Kicking",text="Kicking",command=lambda:click(vvv.get()) )
radioButton3 = Radiobutton(frame2, variable=vvv, value="Pushing ",text="Pushing",command=lambda:click(vvv.get()) )
radioButton4 = Radiobutton(frame2, variable=vvv, value="Forceful",text="Forceful",command=lambda:click(vvv.get()) )
radioButton5 = Radiobutton(frame2, variable=vvv,value="Punching Walls", text="Punching Walls", command=lambda:click(vvv.get()))
radioButton6 = Radiobutton(frame2, variable=vvv,value="Clinch fists ", text="Clinch fists", command=lambda:click(vvv.get()))
radioButton1.pack(side=LEFT)
radioButton2.pack(side=LEFT)
radioButton3.pack(side=LEFT)
radioButton4.pack(side=RIGHT)
radioButton5.pack(side=RIGHT)
radioButton6.pack(side=RIGHT)
frame2.place(x=35, y=355)
buttnn = Button(root, text="Save", width=10, height=2, fg= "blue",command=save_funct)
buttnn.place(x=570, y=615)
root.mainloop()
def st_ii():
print("Redirected")
canvas=Canvas(width=400,height=200, bg="blue")
canvas.place(x=200,y=130)
photo=PhotoImage(file="C:\\Users\\breada\\OneDrive\\Desktop\\Forest.png")
canvas.create_image(0,0,image=photo, anchor=NW)
toolbar = Frame(windo, bg="powder blue", padx=3, pady=20)
insertButt= Button(toolbar,text = "A-Form",command =han)
insertButt.pack(side=LEFT, padx=6,pady=2)
shift_planButt = Button(toolbar, text= "B-Form",command =st_ii)
shift_planButt.pack(side=LEFT, padx=6,pady=2)
toolbar.pack(side=TOP,fill=X)
windo.mainloop()
"""
If you compile your script into an executable file, for example by using "auto-py-to-exe", then the resulting .exe-file can be run on any computer with the same architecture as the one you created the .exe file on.
You can include other files or folders containing pictures or icons using a simple GUI.
you can install it with pip:
$ pip install auto-py-to-exe
or directly from github:
https://github.com/brentvollebregt/auto-py-to-exe

Only open 1 window when button clicked multiple times

I am trying to create a basic invoicing system. However i have encountered an issue as you can tell from my the title, is there any way to achieve this. I have been using a counter to determine if the window should open or not but i dont think it is right.
from tkinter import *
window = Tk()
count = 0
def openNewWindow():
global count
count = count + 1
if count == 1:
newWindow = Toplevel(window)
newWindow.title("New Window")
newWindow.geometry("800x800")
newWindow.title('test ©') # Frame title
newWindow.iconbitmap('icon4.ico') # Frame logo
if 'normal' == newWindow.state():
count = 2
else:
count = 0
width = window.winfo_screenwidth()
height = window.winfo_screenheight()
window.geometry("%dx%d" % (width, height))
bg = PhotoImage(file="bsor.gif")
label_image = Label(window, image=bg)
label_image.place(x=0, y=0)
title_label = Label(window, text="Job Management System", bg="black", fg="white")
title_label.config(font=("Courier", 70))
title_label.place(x=65, y=3)
customer_database_button = Button(window, text="Customer Database", width="23", height="2",
font=('Courier', 13, 'bold'), command=openNewWindow)
customer_database_button.grid(row=3, column=0, pady=185, padx=(110, 0))
employee_database_button = Button(window, text="Employee Database", width="23", height="2",
font=('Courier', 13, 'bold'))
employee_database_button.grid(row=3, column=1, pady=10, padx=(50, 0))
job_category_button = Button(window, text="Job Category (Pricing)", width="23", height="2",
font=('Courier', 13, 'bold'))
job_category_button.grid(row=3, column=2, pady=10, padx=(50, 0))
quote_sale_button = Button(window, text="Quotes / Sales", width="23", height="2", font=
('Courier', 13, 'bold'))
quote_sale_button.grid(row=3, column=3, pady=10, padx=(50, 0))
cash_management_button = Button(window, text="Cash Management", width="23", height="2", font=
('Courier', 13, 'bold'))
cash_management_button.grid(row=3, column=4, pady=10, padx=(50, 0))
analysis_mode_button = Button(window, text="Analysis Mode", width="23", height="2", font=
('Courier', 13, 'bold'))
analysis_mode_button.grid(row=3, column=5, pady=10, padx=(50, 0))
window.title('test') # Frame title
window.iconbitmap('icon4.ico') # Frame logo
window.mainloop()
Here is a minimal example on how to do it (works best with only one additional allowed window):
from tkinter import Tk, Toplevel, Button
def open_window(button):
button.config(state='disabled')
top = Toplevel(root)
top.transient(root)
top.focus_set()
top.bind('<Destroy>', lambda _: btn.config(state='normal'))
root = Tk()
root.geometry('300x200')
btn = Button(root, text='Open new window!', command=lambda: open_window(btn))
btn.pack(expand=True)
root.mainloop()
Just have the function disable the button and bind a <Destroy> event to the Toplevel to set the button's state back to normal. (Also you may want to use .transient on the Toplevel to make it appear above its master so that people don't forget that they haven't closed the window and wonder why they can't press the button (it will also not display additional icon in the taskbar))
Also:
I strongly advise against using wildcard (*) when importing something, You should either import what You need, e.g. from module import Class1, func_1, var_2 and so on or import the whole module: import module then You can also use an alias: import module as md or sth like that, the point is that don't import everything unless You actually know what You are doing; name clashes are the issue.
I strongly suggest following PEP 8 - Style Guide for Python Code. Function and variable names should be in snake_case, class names in CapitalCase. Don't have space around = if it is used as a part of keyword argument (func(arg='value')) but have space around = if it is used for assigning a value (variable = 'some value'). Have space around operators (+-/ etc.: value = x + y(except here value += x + y)). Have two blank lines around function and class declarations.

how to go into another windows in tktinker and destroy the previous window

code
'''here is code for login'''
from tkinter import*
from PIL import ImageTk
from home import product
from tkinter import messagebox
import mysql.connector
try:
mydb1=mysql.connector.connect(
host='localhost',
user='root',
passwd='',
database='gg'
)
mycursor=mydb1.cursor()
except mysql.connector.Error as error:
messagebox.showinfo("Information", "No Server Connection")
exit(0)
class Please_Login:
def __init__ (self,root):
self.root=root
self.root.title("Please Login")
self.root.geometry("640x426+100+50")
self.root.resizable(False, False)
# self.bg=ImageTk.PhotoImage(file='Desktop/sanju.jpg')
# self.bg_image=Label(self.root,image=self.bg).place(x=0,y=0,relwidth=1,relheight=1)
global usename1
global rollno1
#frame login
Frame_login = Frame(self.root, bg="white")
Frame_login.place(x=305,y=70, height=340, width=320)
#label for interface heading
title = Label(Frame_login, text="LOGIN SYSTEM !!", font=("bahnschrift", 15, "bold"),
fg="black", bg="white").place(x=10, y=20)
sam = Label(Frame_login, text="please login in here", font=("arial", 12, "bold"),
fg="black", bg="white").place(x=10, y=50)
self.namevar=StringVar()
self.pwvar=StringVar()
#label and entry for username
self.lbluser = Label(Frame_login, font=('Bahnschrift', 12, "bold"), text="USER NAME:"
, fg="black", bg="white").place(x=10, y=90)
self.txt_username = Entry(Frame_login, font=("Goudy old style", 15), bg="lavender",textvariable=self.namevar)
self.txt_username.place(x=130, y=90, width=170, height=25)
#label and entry for password
self.lbluser = Label(Frame_login, font=('Bahnschrift', 12, "bold"), text="PASSWORD:"
, fg="black", bg="white").place(x=10, y=130)
self.txt_userpw = Entry(Frame_login, font=("Goudy old style", 15), bg="LAVENDER",textvariable=self.pwvar,show="*")
self.txt_userpw.place(x=130, y=130, width=170, height=25)
#login button
self.login = Button(self.root, text="LOGIN", bg="white", fg="black",command=self.loginAdd ,font=("Bahnschrift", 15, "bold"))
self.login.place(x=330, y=250, width=250,height=30)
#sign up button
signup=Button(self.root,text="SIGN UP",bg="white",fg="black",
font=("Bahnschrift",15,"bold")).place(x=330, y=290, width=250, height=30)
#reset button
reset= Button(self.root, text="RESET", bg="white", fg="black",
font=("Bahnschrift", 15, "bold")).place(x=330, y=330, width=250, height=30)
# forget password button
forget = Button(Frame_login, text="Forget Password?", bg="white", fg="black", bd=0,
font=("Bahnschrift", 10, "bold")).place(x=10, y=310)
def loginAdd(self):
username1 = self.txt_username.get()
rollno1 = self.txt_userpw.get()
sql="SELECT * FROM login where username=%s"
value=(username1,)
mycursor.execute(sql, value)
myresult = mycursor.fetchall()
for i in myresult:
id = i[0]
pw = i[1]
if (username1 == "" or rollno1 == ""):
messagebox.showinfo("Information", "Fill all the fields")
elif (username1==id and rollno1==pw):
self.reg = Toplevel(self.root)
self.root.destroy()
product(self.reg)
else:
messagebox.showinfo("Information","enter correct password and username")
root=Tk()
Please_Login(root)
root.mainloop()
'''here is the code for home buttn'''
from tkinter import*
from PIL import ImageTk
import company
import manifest
class product:
def __init__(self, root):
self.root = root
self.root.title("WAREHOUSE MANAGEMENT SYSTEM")
self.root.geometry("1024x768+0+0")
self.root.resizable(False, False)
# self.bg = ImageTk.PhotoImage(file='Desktop/hello.jpg')
# self.bg_image = Label(self.root, image=self.bg).place(x=0, y=0, relwidth=1, relheight=1)
self.b1=Button (self.root,text="COMPANY",command=self.addcompany,font=('bahnschrift',20,'bold'))
self.b2 = Button(self.root,text="MAINFEST",command=self.addcompany,font=('bahnschrift',20,'bold'))
self.b3 = Button(self.root,text="WAREHOUSE",font=('bahnschrift',20,'bold'))
self.b4 = Button(self.root,text="UPDATE",font=('bahnschrift',20,'bold'))
self.b5 = Button(self.root,text="SHIPMENT",font=('bahnschrift',20,'bold'))
self.b6 = Button(self.root,text="QUIT",font=('bahnschrift',20,'bold'))
self.b1.place(x=30, y=50)
self.b2.place(x=30,y=150)
self.b3.place(x=30, y=250)
self.b4.place(x=30, y=350)
self.b5.place(x=30, y=450)
self.b6.place(x=30, y=550)
def addcompany(self):
self.reg = Toplevel(self.root)
company.product(self.reg)
def addmanifest(self):
self.reg = Toplevel(self.root)
manifest.product(self.reg)
From what I can tell of your question, what you want to do is something like:
I don't know classes so you can add them on your own.
def loginaccepted():
home = Toplevel()
root.withdraw()
Toplevel() creates a child of Tk() and root.withdraw() destroys the window. If you want the window back you can use root.deiconify()
Again, I dont understand classes, hopefully this answers your question!

Tkinter lable config dynamically

i want dynamic lable.config is it possible ? because the result doesn't fix with the screen size and the rest of the text are cut off and cannot see. Here is the code. i know my code is not effective but i am a beginner and i have no idea and dont know anything about GUI in python
def link_GUI(graph):
def btn_click():
data1 = str(txtDataEntry.get()) # get data from test box
data2 = str(txtDataEntry2.get())
r_edge = link(graph, data1, data2)
lblResult.config(text="" + data1 + " and " + data2 + " are linked")
lblResult2.config(text="" + str(r_edge))
root = Tk()
root.title("SSM Application")
root.geometry("1500x600")
lblTitle = Label(text=" Link a station to another station", font=('arial', 20, 'bold'), fg='Black')
lblTitle.pack()
lblTitle = Label(text=" *Close the box to choose another option* ", font=('arial', 10, 'bold'), fg='Black')
lblTitle.pack()
frame1 = Frame()
lblDataentry = Label(frame1, text="Enter first station name:", pady=1, fg='black') # 1111111111111111
lblDataentry.grid(row=0, column=0)
txtDataEntry = Entry(frame1) # 111111111111111
txtDataEntry.grid(row=0, column=1)
lblDataentry = Label(frame1, text="Enter second station name:", pady=1, fg='black') # 2222222222222
lblDataentry.grid(row=1, column=0)
txtDataEntry2 = Entry(frame1) # 222222222222222
txtDataEntry2.grid(row=1, column=1)
btnSubmit = Button(frame1, text="Link", bg='grey', fg='black', command=btn_click)
btnSubmit.grid(row=2, column=1)
frame1.pack() # add frame to gui
lblResult = Label(font=('arial', 18, 'bold'), fg='darkblue')
lblResult.pack()
lblResult2 = Label(font=('arial', 18, 'bold'), fg='darkblue')
lblResult2.pack()
root.mainloop()
the original output result1: https://i.stack.imgur.com/ErzL6.png
here is the result after i tried with wrap length but it also cannot help too is there any other ways to do?
https://i.stack.imgur.com/J3eBd.png
change root.geometry("1500x600") to root.minsize(1500, 600) in order to let the root window to expand.
change lblResult2.pack() to lblResult2.pack(fill="both", expand=1), so that lblResult2 will fill the root window width and adjust the root window height in order to show all its content.
change lblResult2.config(text=""+str(r_edge)) to lblResult2.config(text=str(r_edget), wraplength=lblResult2.winfo_width(), justify='left') in order to wrap its content to fit its width.
Edit: Another solution is to use Text widget instead of Label:
change the following lines
lblResult2 = Label(font=('arial', 18, 'bold'), fg='darkblue')
lblResult2.pack()
to
txtResult2 = Text(font=('arial', 18, 'bold'), fg='darkblue')
txtResult2.pack(fill='both', expand=1)
change the following line in btn_click():
lblResult2.config(text=""+str(r_edge))
to
txtResult2.delete(1.0, 'end')
txtResult2.insert('end', str(r_edge))

Categories

Resources