Wednesday, August 30, 2017

Python27: Building a Simple TKinter GUI

Not too long ago, my job required me to build an interactive GUI with Python 2.7. I was limited to using what comes with the basic Python installation, so that the GUI could be used on any computer, so long as Python was installed. This meant that I had to learn how to use Tkinter. If you've never used Tkinter before, I'll just say that it's one of the most frustrating Python modules I've used. It's very difficult to find any tutorials out there that are simple and code-light. After days of non-stop research, I finally pieced together the simplest way to create a Tkinter GUI. I will now relay the code to you.

The absolute simplest you can get for building a Tkinter GUI is the following code that produces the following GUI:

 from Tkinter import * 
 root = Tk() 
 mainloop() 

This GUI will stay open until you close the window. There's not that much to it, but it beats the nonsense of classes that other tutorials will immediately fling you into. So that you're not just thrown to the sharks, I'll explain the different elements of this code.

from Tkinter import * imports everything from the Tkinter module. I like to do this so that I don't end up with a strange error when I run my program that I eventually trace back to not having all the necessary modules imported. Be careful that you don't use tkinter or tk, since using either of those will thrown an error.

root = Tk() is where we define the GUI window. root  is what we call the window and Tk() tells Python that it needs to create a Tkinter window.

mainloop() keeps the GUI from closing itself immediately. Most tutorials I've found that show you how to make a simple Tkinter window will give you a few lines of code, but the GUI will only be open for a defined period of time before closing.

Next, I'll show you an example of a Tkinter GUI with GUI elements, like radio buttons, check boxes, text boxes, and labels.

 from Tkinter import * 
 root = Tk() 
 root.title("Title") 
 Label(root, text="Label").pack() 
 Entry(root).pack() 
 Radiobutton(root, text="Radiobutton").pack() 
 Checkbutton(root, text="Check box").pack() 
 Button(root, text="Button").pack() 
 mainloop() 


This is another bare bones Tkinter example. The input elements won't return values and are arranged based on how the elements are ordered in the code.

root.title("Title") sets the title of the GUI window. The program's code won't refer to the GUI by this name. You must associate the title with a specific window, so that is why root. is added.

.pack() is the simplest way to organize Tkinter GUI elements. The organization is based on the order of the lines of code. For instance, Label is above radio button in the above example code, so the label will appear above the radio button. .pack() isn't very customizable or controllable, but if just want to knock something together quickly, it works well.

Label(root, text="Label") created an uneditable line of text. The element is called Label because it is most frequently used to label another input element, such as a text entry box. The specific GUI window, root in this case, must be referenced so that Python knows what window it is putting the element in. This is the case for all the GUI elements. text= gives you the ability to label the element in the GUI.

Entry(root) makes a text entry box that you can use for data like a username, password, or journal entry. You can assign this element to a variable so your program can access the data entered by the user later in the program.

Radiobutton(root, text="Radiobutton") creates one radio button. If you want to make multiple radio buttons for a single choice, you need to associate them all with one variable. Adding , variable=newVar after text="Radiobutton" is the way to do that. Just be sure to define newVar.

Checkbutton(root, text="Check box") follows the same concepts as the preceding examples. It created a check box. For creating multiple check boxes for the same choice, you can use the same method as I described for radio buttons.

Button(root, text="Button") creates a button that does nothing. If you want it to do something, you create a function with no arguments, then reference that function. For instance, if you wanted to make the button quit the program:
 def dstryGUI(): 
     root.destroy() 
 ... 
 Button(root, text="Quit", command=dstryGUI) 

root.destroy() literally destroys the GUI window. After destroying the GUI window, if there isn't any further code, the program will quit.

Something to be careful of when creating a GUI: the mainloop() function runs the GUI window section of code for an indefinite period of time. That means, if you're trying to run other processes, the other processes won't run until you close the GUI. In fact, other processes, such as other GUI windows, will appear to hang and will become unresponsive. The best way to work around this is to create parallel processes, or multithreading. If you want to learn multithreading, I highly recommend reading this. It's part of an excellent book on Python that taught me most of what I know.

Monday, June 27, 2016

Jack Spicer: An Evil Boy Genius, An Evil Inspiration

Jack Spicer from Xiaolin Showdown, a clip from the TV show
My bestest boyfriend in the whole world got me the perfect Christmas present this year: Season 1 of Xiaolin Showdown on DVD. This is a show that aired around the time that I was ten to thirteen. I loved watching it as a youngster. My favorite character was the comic relief guy, who also happened to be a red-headed Evil Boy Genius.

I'm not generally one to root for the bad guys, but it's hard to resist when they're the paragon of what you want to be. (Aside from being a screamer.) So let's look at what Jack Spicer, Evil Boy Genius has:

  • A evil lair/laboratory
  • Lots of robots
  • Advanced knowledge of physics and mathematics as it relates to ripping a hole in the space-time continuum
  • Artist snobbery
  • An evil laugh
  • Red hair
All good resume material for the up and coming evil mastermind.

I had forgotten about the show until recently, and so was thoroughly enjoying re-watching it. Multiple times. After going through the 1st season a third time, I determined that I was this world's manifestation of Jack Spicer, and that I must become more like him. Which takes me to one of my future projects.

Jack Spicer's HeliBot that he got from his Grandma
when he turned evil.
You can't be Jack Spicer without the HeliBot (his little backpack). This is probably one of main distinguishing characteristics of Spicer. I developed a design that seems pretty practical (at least for a costume) and that would be slightly complicated to make. Making the pack would involve my welding, soldering, and circuit design skills.

I wasn't a welder until fairly recently, when I took a creative metal design class. I got to experience the joys of the oxy-acetylene and Mig welders, although the things I created were never really practical. Sort of like Jack's semi-useless robots. When making Jack's HeliBot, I would be using my welding skills to create the shell, creating welds where you can see the lines in the above image. I figured I'd do it this way so that I didn't have to do much metal dishing. And, fortunately, I'm just strong enough that I can bend steel with my hands, something that Jack may or may not be able to do. For the metal I'd use, I'm torn between steel and aluminum. I've never welded aluminum, so I don't know how it would go. Steel would be easy enough to weld, but would end up being pretty heavy, even if I used a thin gauge.

With my soldering and circuit design skills, I would be figuring out how to get my Propeller micro-controller to run a couple little DC motors. I figure I would use the motor as the means to extend the stocks and props for the HeliBot. I'm still not entirely sure how I would make the mechanism to extend the stocks, but the props themselves will be easy enough to run. My circuit designing skills are a bit limited, but, with a manual and Google on hand, I could come up with the ideal design for connecting my MC to the rest of the circuit. I think my biggest concern with the circuit will be how to provide enough power to the motors without frying my little Propeller MC. We will see...

And, finally, the HeliBot would not be complete without a watch to tell it when to extend the props and get them spinning. When I went to visit Parallax last year, I got one of the people there excited enough that he took me into the back room and let me pick from a selection of discarded modules, electronic components, and manuals. That was a good day. In the back room, there was pretty much everything I needed, the main of which was a WiFi and bluetooth module, which are the exact modules I'll need for making a watch to communicate with my HeliBot. The only thing I'm missing now is a screen for the watch and some free time to build it all.

Monday, June 20, 2016

Fun with CSS3

I went through a revamp of my website, NinjaObsessed.com, about a year ago. The design was getting a bit stale for my tastes and didn't have the flair that other sites have. The organization of my HTML had gotten pretty out of hand, too, from all the edits and minor revisions that I made while trying to avoid a complete overhaul. Eventually, I made time to fix my website.

What bugged me the most about my older websites was that I had to use JavaScript to make my drop-down navigation menus. I don't generally think much of JavaScript, since it can get needlessly complicated very quickly. And this comes from a girl that's programmed in Java, C, Basic, PBasic, Python, and Propeller.

When I was tweaking my website a little while back, I had to look up some CSS notation. I generally go to W3Schools, since they give the most direct and simple answers. I saw the little demos they had on the main page for the pure CSS animations and got pretty fan girl excited. I've been animating since I was fourteen and have always loved the art form. Seeing that I had the potential to use CSS to create animations was the team up of my two loves: art and coding.

CSS has come a long way since when I first started web developing 10 years ago, as have my web design skills. CSS was a bit limited, but was still pretty powerful. Only needing to edit a few lines of code in a file separate from your HTML source code made it much easier to update my website's look as my design skills developed. Before I learned CSS, it was easy to miss a tag that would mess up the whole rest of the site if left behind during a revamp.

The update to CSS3 has made web design even simpler, since it eliminates the need for most Javascript. Animating a navigation bar with CSS takes only two or three lines of code, rather than the block of 5 or more lines in Javascript. Not only can you animate a nav. bar, you can also animate a little game with an animated avatar, like on this site. Apparently, I'm not the only animation nerd out there.

Web designing is rad and the tools for it just get better an better. I'm looking forward to seeing what new CSS tricks will be developed in the future.

Monday, June 13, 2016

The Power of the 10 Minute Cartoon

Since I'm a student animator, I'm a big fan of cartoons. I always have been. Whenever I have some spare time, I like to sit down and binge watch kids cartoon shows. My absolute favorite cartoon show is a tie between Gravity Falls and Teen Titans (OS). But these are both ~30 minute long cartoons, which is necessary for the story they're telling. Both Teen Titans and Gravity Falls are plot driven shows. What I want to talk about is 10 minute cartoons.

10 minute cartoons are a cool thing. One of the first 10 minute cartoons I remember watching was 'My Life as a Teenaged Robot.' This was a 20 minute show with two 10 minute segments. The stories were generally pretty light; quick little vignettes and sketches with no continuity from one to the next. My most recent obsession is Steven Universe, a continuing three season long cartoon show with individual 10 minute episodes. I watch all of my TV online, so I don't know if they play two episodes together or not on TV, but each episode has an intro and credit sequence, which suggests not. If I'd gone back in time and tried to tell myself how powerful a 10 minute cartoon show could be, I wouldn't have believed myself. It took watching several episodes to convince myself of that. So that you can understand why I think 10 minute cartoons can be so powerful, I'm going to take a brief segue into movies and scripts.

If you're a script writer, the ultimate reference for making a great script is Blake Snyder's Save the Cat. In this book, Snyder presents an outline that every successful movie should follow. If the outline is followed exactly, the script can become a movie that leaves the audience satisfied and happy. Snyder explains why the outline works for stories and also says that following the outline gives you a way to prove that the script is your own, in case some one tries to rip off your idea. Blake Snyder simplifies the outline to a 'beat sheet' in his book, with each 'beat' being a major plot point. Not only is the beat sheet great for movies, it can also work for books, television shows, and cartoons. A satisfying story can be told through any of those mediums. Since I'm an amateur writer, Save the Cat  is a book I've studied. Out of curiosity one night, I decided to sit down in front of a few Steven Universe episodes to see if each episode hit each beat. Each episode I had watch felt full-length, rather than the short 10 minutes that it actually was, so that made me wonder if they were applying Snyder's outline. (Or maybe I'm just a spaz and can't sit still for longer than 10 minutes.) To my surprise and delight, the three episodes I plotted all hit each beat. Each beat was clear and distinct. In movies, it can be hard to find each beat the first time watching it, but I figure this is because a movie has more time to develop each plot point that you can look at at the end of the movie and then recognize them. Short cartoon shows have to be a lot more direct so that you don't get lost.

Not every 10 minute cartoon uses the Blake Snyder Beat Sheet outline. Not every cartoon needs to. Adventure Time, for example, is closer in character to the Teenaged Robot show I mentioned earlier. Each episode is more of a quick sketch,with no real continuity between episodes (at least for the first two seasons). Adventure Time is a good example of a joke driven show, where each episode is a build up with a joke for a punchline at the end. We Bare Bears appears to be a simpler outline than Snyder's for each episode, although I haven't plotted any of them out. I suspect the outline is truncated.

Seeing how powerful and interesting a 10 minute cartoon can be gives me hope. My eventual goal is to become an animator and hopefully create my own animated series. If I start a cartoon show more or less on my own, it would be impossible for me to regularly create a 30 minute show every month, let alone every week. A 10 minute format would be much more feasible.

Wednesday, June 8, 2016

Fringe: Interesting, But Inaccurate

Recently, I decided that it was time to take a break from watching kids cartoons and to start watching a 'grownup' show. I recently subscribed to Amazon Prime (Great service. I highly recommend it.) and looked at its suggestions for me. It recommended that I check out Fringe. From what I saw in the description, it looked to be an interesting enough show, so I decided to check it out. It held my interest for 3 seasons.

The premise of Fringe is that there is an FBI division called the 'Fringe Division' that handles strange occurrences that can only be explained by fringe science. A determined young FBI investigator, Olivia Dunham, begins noticing a 'pattern' of strange, fringe occurrences. She becomes curious and begins investigating them on her own. After having a good deal of success in her investigations, she's offered a position in the fringe division. Further investigation leads her to believe that a crazy, old ex-scientist named Walter is linked to all of the occurrences, and so she gets his shady son to release him from the mental institution he resides at. From there, the investigations into the strange and paranormal begin.

The show has a premise that I find relatively interesting, although majorly bogus. Many of the fringe occurrences they come across are physically and medically impossible. Also, Walter, the supposedly brilliant scientist, regularly substitutes 'theory' for 'hypothesis.' For those of you that aren't acquainted with the scientific terms, a hypothesis is an initial concept that needs to be tested and either proved or disproved. A theory is a concept that has been tested rigorously and appears to be accurate for all intents and purposes, but still has the possibility of being inaccurate. A law is an immutable concept that is constant and cannot be disproven. This is a common layman mistake to call a hypothesis a theory.

If you ignore the scientific, medical, and terminological fallacies, it is a relatively good show. The characters are interesting and believable. The main character, Olivia, is a character that's easy to identify and sympathize with. Walter is a bit of a stereotype, but not obnoxiously so. Peter is a fun character and plays off of Olivia well. Also, the most exciting part of the show for me, Leonard Nimoy is a key character, although he doesn't get much screen time. Of all the actors, I would definitely say his acting is the best, but, as an OS Star Trek fan, I may be biased.

I think the most disappointing part of the show for me is the over-arching plot line. I like the plot lines of the individual episodes the best. The over-arching plot of the series feels over dramatic and is, honestly, not that interesting. What kept me watching for three seasons was the characters and their fun and amusing interactions. I would recommend this show for others, especially if the paranormal and strange interest you. It's also fun for anyone that doesn't get easily annoyed with factual inaccuracies. I liked it alright!

Monday, May 9, 2016

Marvel's Civil War: More Like a Small Scuffle

So on Friday, I put on my Deadpool costume and headed out with a group of friends to see Marvel's newest movie, Captain America: Civil War. Unfortunately, it lived down to my expectations. As I understand it, the original Civil War timeline from the comic books was more like an actual civil war, with huge amounts of supers fighting against each other, rather than the 10 or so Avengers having a minor scuffle. This was pretty disappointing for me. Not to mention that having superheros fighting with each other isn't really all that exciting. I'm pretty sure that Captain America and Tony Stark could have just hugged it out.

The most exciting part of the movie for me was when we got to meet the new Spiderman. It's kind of silly that we have had three different renditions of Spiderman in the last 14 years. I'm very sad that we'll never see anymore 'The Amazing Spiderman' movies with Garfield. They were all very solid Spiderman movies in my opinion. I guess I'm going to have to settle for the end of the series as depicted in HISHE, where Superman went back in time and saved Gwen. Dispite my disappointment, there's certainly something to be said for a Spiderman that is actually a teenager. I can tell you that I'm a little sick of Hollywood, Disney, and everyone else casting 30+ year-old actors as high schoolers. There are plenty of good child actors out there.

While Civil War was a disappointment, it had it's moments of greatness that will keep me coming back to see Marvel's Avengers movies. The fight scenes were interesting and the graphics were great. I thought it was kind of stupid to have all the heroes charging each other face on, though. I suspect that scene was only there to make the previews seem more exciting. That sort of scene is what you put on the front of a comic book to quickly tell readers what they can expect and to get them excited about the story line. In reality, a head on charge is not a strong combat maneuver.

Overall, the movie was a bit of a disappointment. I wouldn't say that it's not worth seeing, unless you're someone that's easily disgusted by crappy plots. The characters' actions were forced and were poorly written in some scenes, but were dead-on to the characters' personalities in others. The ending was disappointing and unsatisfying, but there were a lot of people that enjoyed it anyways. Most of the people that saw this movie in the theater with me, including all my friends, loved the movie. If you're a teenager or a twenty-thirty something, you'll doubtless enjoy this movie. I'm in that age category, but I'm more critical of movies than most people.

If nothing else, see this movie for Spiderman, Deadpool approved.

Friday, May 6, 2016

Sports Lockouts

The effect of sports on the economy is an interesting problem that I had never considered until I started looking more in sports lockouts. While they can affect the excitement and enjoyment of the fans and the team’s rank that season, lockouts can have a positive impact on the economy. In a paper by Coates and Humphreys, it states, “An examination of the impact of past work stoppages in professional [sports] can shed some light on the potential impact of ... professional sports as engines of economic growth in cities.” (Coates and Humphreys 2001, 737) You would think that having a sports team coming into town would increase the influx of money into a given city, boosting the economy, at least temporarily. But Coates’ and Humphreys’ tentative findings seem to indicate otherwise. "Although imprecisely estimated, the parameters on the strike variables suggest that real per capita income rises in SMSAs during years that the professional sports teams in these SMSAs are on strike. ... Several possible explanations exist for our results. One is substitution in private spending. Fans could alternatively go out to dinner and a movie of go bowling during a sports strike. If these activities have higher local spending multipliers than does spending on professional sports, then income could be higher during strikes.

Differences in the impact of public and private spending represents a second explanation. Professional sporting events increase metropolitan government spending by driving up spending on public safety, crowd and traffic control, and so on. I this category of public spending declines during a strike and the metropolitan government either borrows less or collects fewer taxes or fees as a result of this decrease in spending, then additional money will remain in the pockets of private citizens. Furthermore, if the marginal impact of these additional private dollars exceeds the marginal impact of these dollars in public hands, then total income in the metropolitan area would increase. There would also be a decrease in deadweight loss in this case." So it’s possible that, rather than one of professional sports’ many flaws, professional sports itself is the problem, in the case of economy. That’s not to say that all of our country’s debt could be wiped away by killing all professional sports. The per capita income increase recorded in Coates’ article was less than 1%.

There’s no real way to ‘solve’ the decrease in average income when a sports event is happening. Professional sports culture has been ingrained in American culture since at least the 1940s. However, it is interesting to note that sports aren’t the economic stimulator that most people could assume that they are.






Coates, Dennis, and Brad R. Humphreys. 2001. “The Economic Consequences of Professional Sports Strikes and Lockouts”. Southern Economic Journal 67 (3). Southern Economic Association: 737–47. doi:10.2307/1061462.