Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Combining 2 scripts
#1
I am creating a display with my friend to display some information on a screen. He is coding the information (like a clock, and newsfeed and stuff like that) while I am displaying it. So he gives me scripts and I am combining them into one script basically. The problem is I am very new to python and cannot figure out how to add this particular script to mine. Here are the two scripts in full with mine first and the one I want to add to mine next (There are two places in the scripts which you may not have, there is the background picture I am using (0.png) and there is also supposed to be a link to a news api in the other script but the site wont let me post it. If you are running it you will have to insert the bbc news api into that place.):
from tkinter import *
from PIL import ImageTk, Image
import os
import time
import requests
import tkinter as tk

class App(tk.Tk):
    def __init__(self):
        # call the __init__ method of Tk class to create the main window
        tk.Tk.__init__(self)
        
        # background image
        img = ImageTk.PhotoImage(Image.open("0.png"))
        panel = Label(self, image=img)
        panel.pack()
        
        # clock
        self.label = tk.Label(self, text="", font=('comic',50,'bold'),
                              bg='#464545', fg='#1681BE')
        self.label.place(height=204, width=484, x=1384, y=824)       
        self.update_clock()
        
        # window geometry
        w, h = self.winfo_screenwidth(), self.winfo_screenheight()
        self.geometry("%dx%d+0+0" % (w, h))

        self.overrideredirect(True)
        self.mainloop()

    def update_clock(self):
        now = time.strftime('%H:%M:%S')
        self.label.configure(text=now)
        self.after(1000, self.update_clock)

app = App()
import requests
import tkinter as tk

response = requests.get("this is a link to the news api")

data = response.json()

Run = ""

for item in data ['articles']:
    Run +=(item["description"]+ " ")
  

root = tk.Tk()
deli = 100           # milliseconds of delay per character
svar = tk.StringVar()
labl = tk.Label(root, textvariable=svar, height=10 )

def shif():
    shif.msg = shif.msg[1:] + shif.msg[0]
    svar.set(shif.msg)
    root.after(deli, shif)

shif.msg = Run
shif()
labl.pack()
root.mainloop()
I don't quite know how the class function works and I'm having trouble combining them around that. Thank you for any help and ask me anything I didn't include.
Reply
#2
Import is here. You can use import statement at the beginning in your script to import his one. Without the file ext.!
If your friend script is information.py
import information
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Reply
#3
No that doesn't seem to be working
Reply
#4
Well, the Python modules are almost just that.

information.py
from bs4 import BeautifulSoup
import requests

def get_secret(url):
    html = requests.get(url).content
    soup = BeautifulSoup(html, 'lxml')

    secret = soup.find_all('div', _class='kill_all_humans_plan').text
    return secret
your_script.py
import information

for p in information.get_secret('http://www.veryevilpeople.org/'):
    print(p)
In this scenario, both scripts have to be in the same directory
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Reply
#5
@wavic, did you even look at the two scripts and that they are tkinter GUI? In addition the way they are written does not make the import relatively easy....
Reply
#6
@buran, no, I didn't. I speak in common point view. I don't know Tkinter.
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Newbie help combining two scripts emuola 13 4,513 Oct-04-2020, 12:09 PM
Last Post: scidam

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020