How to run python file in Tkinter

2024/11/16 1:26:24

I'm a beginner in Python, hence the question. i would like to run a python file (smileA.py) in Tkinter. How would i start?

I do not wish for it to run when clicking a button, but the file to run automatically in the Tkinter itself.

Thanks.

Answer

What you need a module called subprocess, which will allow you to run files, from within your python code, by using Popen.

The code for running the file will look something like this, once you import the module:

from subprocess import Popenp = Popen("smileA.py")
stdout, stderr = p.communicate()

If that's what you mean by "Running it in Tkinter", as in, running that code, while building a GUI in Tkinter in the same file.

https://en.xdnf.cn/q/118982.html

Related Q&A

Discord.py Cogs “Command [ ] is not found”

I am recoding my discord.py bot using cogs as it wasnt very nice before. I tried this code: import discord import os import keep_alive from discord.ext import commands from discord.ext.commands import …

Binomial distribution CDF using scipy.stats.binom.cdf [duplicate]

This question already has answers here:Alternatives for returning multiple values from a Python function [closed](14 answers)Closed 2 years ago.I wrote below code to use binomial distribution CDF (by u…

How to get Cartesian product of two iterables when one of them is infinite

Lets say I have two iterables, one finite and one infinite:import itertoolsteams = [A, B, C] steps = itertools.count(0, 100)I was wondering if I can avoid the nested for loop and use one of the infinit…

Function to create nested dictionary from lists [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.This question was caused by a typo or a problem that can no longer be reproduced. While similar q…

Pygame not using specified font

So I am having a problem in pygame where I specify the font and size to use, but when my program is run, the font and size are the default.Here is where I define the textdef font(self):*****FATAL - THI…

port management in python/flask application

I am writing a REST API using the micro framework Flask with python programming language. In the debug mode the application detect any change in source code and restart itself using the same host and p…

using def with tkinter to make simple wikipedia app in python

I am beginner in python. I am trying to make a python wiki app that gives you a summary of anything that you search for. My code is below:import wikipediaquestion = input("Question: ")wikiped…

Only length-1 arrays can be converted to Python scalars with log

from numpy import * from pylab import * from scipy import * from scipy.signal import * from scipy.stats import * testimg = imread(path) hist = hist(testimg.flatten(), 256, range=[0.0,1.0])[0] hist…

Deploying Django with apache using wsgi.py

Im trying to deploy a Django project on a linode server that has apache, some other django projects and a php project on it. Also my project is in a virualenv and the other django projects arent.My Dja…

Building a decision tree using user inputs for ordering goods

I am trying to program a decision tree to allow customers to order goods based on their input. So far, I have devised a nested if-elif conditional structure to decide if customer want to order what or…